From 6ffaff25d967ac8eea98beafe231d9748c9f69b4 Mon Sep 17 00:00:00 2001
From: Tiago Freitas Pereira <tiagofrepereira@gmail.com>
Date: Sat, 28 Feb 2015 17:12:45 +0100
Subject: [PATCH] Solved memory leaks found in the test
 bob.lear.em.test.test_gmm

---
 bob/learn/em/cpp/GMMMachine.cpp |  5 ++++-
 bob/learn/em/gmm_machine.cpp    |  9 +++------
 bob/learn/em/gmm_stats.cpp      | 12 +++++++++++-
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/bob/learn/em/cpp/GMMMachine.cpp b/bob/learn/em/cpp/GMMMachine.cpp
index 7b8b3da..a3cbe44 100644
--- a/bob/learn/em/cpp/GMMMachine.cpp
+++ b/bob/learn/em/cpp/GMMMachine.cpp
@@ -31,6 +31,7 @@ bob::learn::em::GMMMachine::GMMMachine(const GMMMachine& other)
   copy(other);
 }
 
+
 bob::learn::em::GMMMachine& bob::learn::em::GMMMachine::operator=(const bob::learn::em::GMMMachine &other) {
   // protect against invalid self-assignment
   if (this != &other)
@@ -91,7 +92,9 @@ void bob::learn::em::GMMMachine::copy(const GMMMachine& other) {
   initCache();
 }
 
-bob::learn::em::GMMMachine::~GMMMachine() { }
+
+bob::learn::em::GMMMachine::~GMMMachine() { 
+}
 
 
 /////////////////////
diff --git a/bob/learn/em/gmm_machine.cpp b/bob/learn/em/gmm_machine.cpp
index fc27dec..51bcc26 100644
--- a/bob/learn/em/gmm_machine.cpp
+++ b/bob/learn/em/gmm_machine.cpp
@@ -720,16 +720,13 @@ static PyObject* PyBobLearnEMGMMMachine_get_gaussian(PyBobLearnEMGMMMachineObjec
 
   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &i)) return 0;
  
-  boost::shared_ptr<bob::learn::em::Gaussian> gaussian = self->cxx->getGaussian(i);
-
   //Allocating the correspondent python object
   PyBobLearnEMGaussianObject* retval =
     (PyBobLearnEMGaussianObject*)PyBobLearnEMGaussian_Type.tp_alloc(&PyBobLearnEMGaussian_Type, 0);
 
-  retval->cxx = gaussian;
-   
-  //return reinterpret_cast<PyObject*>(retval);
-  return Py_BuildValue("O",retval);
+  retval->cxx = self->cxx->getGaussian(i);
+
+  return Py_BuildValue("N",retval);
 
   BOB_CATCH_MEMBER("cannot compute the likelihood", 0)
 }
diff --git a/bob/learn/em/gmm_stats.cpp b/bob/learn/em/gmm_stats.cpp
index cda8d38..9bf07bd 100644
--- a/bob/learn/em/gmm_stats.cpp
+++ b/bob/learn/em/gmm_stats.cpp
@@ -84,13 +84,23 @@ static int PyBobLearnEMGMMStats_init_hdf5(PyBobLearnEMGMMStatsObject* self, PyOb
 
   char** kwlist = GMMStats_doc.kwlist(2);
 
+  /*
   PyBobIoHDF5FileObject* config = 0;
   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, &PyBobIoHDF5File_Converter, &config)){
     GMMStats_doc.print_usage();
     return -1;
   }
+  */
 
-  self->cxx.reset(new bob::learn::em::GMMStats(*(config->f)));
+  PyObject* config = 0;
+  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &PyBobIoHDF5File_Type, &config)){
+    GMMStats_doc.print_usage();
+    return -1;
+  }
+  
+  auto h5f = reinterpret_cast<PyBobIoHDF5FileObject*>(config);  
+  
+  self->cxx.reset(new bob::learn::em::GMMStats(*(h5f->f)));
 
   return 0;
 }
-- 
GitLab