title: Tracking down Valgrind 40 bytes in 1 blocks are definitely lost in loss record
body: <p>I am new to Valgrind (and my C/C++ is rusty) and I am getting an error:</p>
  
  <pre><code>40 bytes in 1 blocks are definitely lost in loss record 35 of 111
  ==26930==    at 0x4C275C2: operator new(unsigned long) (vg_replace_malloc.c:261)
  ==26930==    by 0x5EFAFDB: cassie_init_with_timeout (cassie.cc:49)
  ==26930==    by 0x46E647: ngx_cassandra_upstream_get_peer (ngx_cassandra_upstream.c:274)
  ==26930==    by 0x41E00B: ngx_event_connect_peer (ngx_event_connect.c:25)
  </code></pre>
  
  <p>I am guessing that the char *last_error_string is giving me fits, but how do I track this down?</p>
  
  <p>Here is my source:</p>
  
  <p>Creation of the Cassie object:</p>
  
  <pre><code>cassie_t cassie;
  
  char *error = NULL;
  cassie = new Cassie(host,port,error,CASSIE_ERROR_NONE);  /* this is line 49 in the above valgrind trace */
  cassie-&gt;cassandra               = cassandra;
  </code></pre>
  
  <p>cassie_t is a struct of an Object.  </p>
  
  <pre><code>typedef struct Cassie *cassie_t;
  </code></pre>
  
  <p>I have this because I am wrapping a C++ lib in order to call it from C.</p>
  
  <p>Here is our object cassie_private.h</p>
  
  <pre><code>#include &lt;string&gt;
  #include "libcassandra/cassandra.h"
  #include "libcassie/cassie.h"
  
  #ifdef __cplusplus
  namespace libcassie {
      using namespace std;
      using namespace boost;
      class Cassie
      {
        // TODO do we need the host and the port??
        public:
              const char*     host;
          int             port;
          cassie_error_code_t last_error_code;
          char*           last_error_string; /* I am guessing my memory problem is here */
          tr1::shared_ptr&lt;libcassandra::Cassandra&gt;                    cassandra;
  
          Cassie();
          Cassie(const char *&amp;host, int &amp;port,char* &amp;in_error_str, cassie_error_code_t error);
          ~Cassie();
      };
  #else
      typedef
           struct Cassie
             Cassie; /* this is for in C */
  #endif
  
  }
  
  #endif
  </code></pre>
  
  <p>Here is cassie_private.cc</p>
  
  <pre><code>#include "cassie_private.h"
  
  namespace libcassie {
  
  using namespace std;
  using namespace libcassandra;
  
  Cassie::Cassie() :
      host(),
      port(0),
      last_error_code(),
      last_error_string(NULL),
      cassandra()
  {}
  
  Cassie::Cassie(const char * &amp;in_host, int &amp;in_port, char* &amp;in_error_str, cassie_error_code_t error) :
          host(in_host),
          port(in_port),
          last_error_code(error),
          last_error_string(in_error_str),
          cassandra()
  {}
  
  Cassie::~Cassie() {
      if(last_error_string) delete last_error_string;
  }
  
  }
  </code></pre>
  
  <p>This is being called in order to delete the Object at the end of use:</p>
  
  <pre><code>void cassie_free(cassie_t cassie) {
  
      if(!cassie) return;
      cassie-&gt;~Cassie();
      if(cassie) delete cassie;
  
  }
  </code></pre>
  
  <p>How do I track this memory leak down?</p>