title: Memory Core Dump C++
body: <p>Now, I have called python to C++. Using ctype to connect between both of them. And I have a problem about core dump when in running time.</p>
  
  <p>I have a library which is called "libfst.so"
  This is my code.
  NGramFST.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  class NGramFST{
  private:
      static NGramFST* m_Instace;
  
  public:
      NGramFST(){
      }
  
      static NGramFST* getInstance() {
          if (m_Instace == NULL){
              m_Instace = new NGramFST();
          }
          return m_Instace;
      }
  
      double getProbabilityOfWord(std::string word, std::string context) {
          std::cout &lt;&lt; "reloading..." &lt;&lt; std::endl;
          return 1;
      }
  
  };
  </code></pre>
  
  <p>NGramFST.cpp</p>
  
  <pre><code>#include "NGramFST.h"
  NGramFST* NGramFST::m_Instace = NULL;
  
  extern "C" {
      double FST_getProbability(std::string word, std::string context){
          return NGramFST::getInstance()-&gt;getProbabilityOfWord(word, context);
      }
  }
  </code></pre>
  
  <p>And this is my python code.</p>
  
  <pre><code>from ctypes import cdll
  lib = cdll.LoadLibrary('./libfst.so')
  
  #-------------------------main code------------------------
  class FST(object):
      def __init__(self):
          print 'Initializing'
  
      def getProbabilityOfWord(self, word, context):
          lib.FST_getProbability(word, context)
  
  fst = FST()
  print fst.getProbabilityOfWord(c_wchar_p('jack london'), c_wchar_p('my name is'))
  </code></pre>
  
  <p>This is error</p>
  
  <pre><code>terminate called after throwing an instance of 'std::bad_alloc'
    what():  std::bad_alloc
  Aborted (core dumped)
  </code></pre>
  
  <p>I reviewed again but I can not detect where is my problem. </p>