title: using electric fence in a c++ program
body: <p>I've been experimenting with Electric Fence lately and I can't figure out how to use it with c++ code.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>// test.cpp
  #include &lt;cstdlib&gt;                                                                                                                                         
  
  using namespace std;                                                                                                                                       
  
  int main()                                                                                                                                                 
  {                                                                                                                                                                                                                                                                                                     
          int *a = new int(10);                                                                                                                              
          delete a;                                                                                                                              
  }  
  </code></pre>
  
  <p>I compiled it with </p>
  
  <pre><code>g++ ./test.cpp -o test -lefence -L/home/bor/efence_x86_64/lib -lpthread
  </code></pre>
  
  <p>And I don't see Electric Fence banner at the start and can't find EF symbols in the executable (using nm command).</p>
  
  <p>But if I modify a program like so:</p>
  
  <pre><code>// test.cpp
  #include &lt;cstdlib&gt;                                                                                                                                         
  
  using namespace std;                                                                                                                                       
  
  int main()                                                                                                                                                 
  {                                                                                                                                                          
          char *p = (char*)malloc(20);                                                                                                                       
          free(p);                                                                                                                                           
          int *a = new int(10);                                                                                                                              
          delete a;
  }
  </code></pre>
  
  <p>everything is good - EF appears. I know it kinda solves the problem, I know :). I just want to understand why it didn't work in the first place, because <code>new()</code> should call <code>malloc()</code>, and <code>delete()</code> calls <code>free()</code>, no?</p>
  
  <p>The reason I got into this is a big project using <em>boost</em> libraries and several others. And this program never calls <code>malloc()</code> or <code>free()</code> directly. And when I build it with EF not I only linked EF to the final executable but rebuilt all the libraries trying to link EF to them. And I can't find EF symbols in either one of them. Is it the right approach? Or is it wrong and EF only should be linked to the executable in the end, the libs should be left intact? But again I can't find EF symbols in the executable then.</p>