CID 1366841 and 1366842 fixed 77/18777/2
Clément DAVID [Thu, 8 Dec 2016 14:23:19 +0000 (15:23 +0100)]
Change-Id: Ie2e82b222795c052f4725073fd7a99f733c6110f

scilab/modules/api_scilab/src/cpp/api_stack_boolean_sparse.cpp

index 64e8b8b..2e9fa1e 100644 (file)
@@ -61,22 +61,17 @@ SciErr getBooleanSparseMatrix(void* _pvCtx, int* _piAddress, int* _piRows, int*
     types::SparseBool* pSpBool = ((types::InternalType*)_piAddress)->getAs<types::SparseBool>();
     *_piNbItem = (int)pSpBool->nbTrue();
 
-    if (_piNbItemRow == NULL)
+    if (!sciErr.iErr && _piNbItemRow != NULL)
     {
-        return sciErr;
+        int* piNbItemRows = (int*)MALLOC(sizeof(int) **_piRows);
+        *_piNbItemRow = pSpBool->getNbItemByRow(piNbItemRows);
     }
-
-    int* piNbItemRows = (int*)MALLOC(sizeof(int) **_piRows);
-    *_piNbItemRow = pSpBool->getNbItemByRow(piNbItemRows);
-
-    if (_piColPos == NULL)
+    if (!sciErr.iErr && _piColPos != NULL)
     {
-        return sciErr;
+        int* piColPos = (int*)MALLOC(sizeof(int) **_piNbItem);
+        *_piColPos = pSpBool->getColPos(piColPos);
     }
 
-    int* piColPos = (int*)MALLOC(sizeof(int) **_piNbItem);
-    *_piColPos = pSpBool->getColPos(piColPos);
-
     return sciErr;
 }
 
@@ -205,20 +200,26 @@ SciErr readNamedBooleanSparseMatrix(void* _pvCtx, const char* _pstName, int* _pi
     SciErr sciErr       = sciErrInit();
     struct Attr
     {
-        public:
-            int *piAddr;
-            int *piNbItemRow;
-            int *piColPos;
-            Attr() : piAddr(NULL), piNbItemRow(NULL), piColPos(NULL) {}
-            ~Attr()
+    public:
+        int *piAddr;
+        int *piNbItemRow;
+        int *piColPos;
+        Attr() : piAddr(NULL), piNbItemRow(NULL), piColPos(NULL) {}
+        ~Attr()
+        {
+            if (piNbItemRow)
+            {
+                FREE(piNbItemRow);
+            }
+            if (piColPos)
             {
-                if(piNbItemRow)
-                    FREE(piNbItemRow);
-                if(piColPos)
-                    FREE(piColPos);
-                if(piAddr)
-                    FREE(piAddr);
+                FREE(piColPos);
             }
+            if (piAddr)
+            {
+                FREE(piAddr);
+            }
+        }
     };
     struct Attr attr;
     sciErr = getVarAddressFromName(_pvCtx, _pstName, &attr.piAddr);