memory leak fixed in library management. 22/16522/3
Cedric Delamarre [Thu, 28 May 2015 12:19:58 +0000 (14:19 +0200)]
cd TMPDIR;
mputl(["function ret = lib_test";"  ret= ""lib1""";"endfunction"], "lib_test.sci");
genlib("lib1lib",TMPDIR,%f,%t);

Change-Id: I2dc68bb459d33e4f4246bc59e93d8d8583412b1d

scilab/modules/ast/src/cpp/symbol/context.cpp
scilab/modules/io/sci_gateway/cpp/sci_load.cpp
scilab/modules/io/src/cpp/loadlib.cpp

index c71f742..001ec90 100644 (file)
@@ -111,13 +111,15 @@ bool Context::clearCurrentScope(bool _bClose)
                 types::InternalType * pIT = pSV->m_pIT;
                 if (pIT->isLibrary())
                 {
+                    // at scilab exit, pIT have a ref == 2 because
+                    // it is contains in libraries and variables.
+                    // call remove will set ref to 1 then the next
+                    // pIT->DecreaseRef(); pIT->killMe(); will delete it.
                     libraries.remove(var.first, m_iLevel);
                 }
-                else
-                {
-                    pIT->DecreaseRef();
-                    pIT->killMe();
-                }
+
+                pIT->DecreaseRef();
+                pIT->killMe();
 
                 var.second->pop();
                 delete pSV;
index 6dca744..181faac 100644 (file)
@@ -78,6 +78,7 @@ Function::ReturnValue sci_load(types::typed_list &in, int _iRetCount, types::typ
                 return Function::Error;
             }
             FREE(pwstPathLib);
+            lib->killMe();
         }
     }
     else
index 3e73d6b..e8fbbcc 100644 (file)
@@ -112,6 +112,7 @@ types::Library* loadlib(std::wstring _wstXML, bool _isFile, bool _bAddInContext)
                 xmlXPathFreeContext(xpathCtxt);
             }
             xmlXPathFreeObject(xpathObj);
+            delete lib;
             return NULL;
         }
     }
@@ -194,7 +195,6 @@ types::Library* loadlib(std::wstring _wstXML, bool _isFile, bool _bAddInContext)
             delete lib;
             lib = NULL;
         }
-
     }
 
     xmlFreeDoc(doc);