xend : strdup may complain about some NULL string. 06/9006/2
Bruno JOFRET [Fri, 14 Sep 2012 08:37:13 +0000 (10:37 +0200)]
Change-Id: I49f637c5d57b3a162e6c7cf0829beb6448bb53ed

scilab/modules/graphic_export/sci_gateway/cpp/sci_xend.cpp

index 1f37366..7b3b12c 100644 (file)
@@ -29,21 +29,26 @@ int sci_xend(char * fname, unsigned long fname_len)
 {
     CheckInputArgument(pvApiCtx, 0, 0);
 
-    char* uid = strdup(ScilabView::getCurrentFigure());
+    const char* pstCurrentFigureReference = ScilabView::getCurrentFigure();
 
-    if (uid)
+    if (pstCurrentFigureReference != NULL)
     {
-        char * ret = org_scilab_modules_graphic_export::Driver::end(getScilabJavaVM(), uid);
-        ScilabView::deleteObject(uid);
+        char* uid = strdup(pstCurrentFigureReference);
 
-        if (*ret != '\0')
+        if (uid)
         {
-            free(uid);
-            Scierror(999, _("%s: An error occurred: %s\n"), fname, ret);
-            return 0;
+            char * ret = org_scilab_modules_graphic_export::Driver::end(getScilabJavaVM(), uid);
+            ScilabView::deleteObject(uid);
+           free(uid);
+
+            if (*ret != '\0')
+            {
+                Scierror(999, _("%s: An error occurred: %s\n"), fname, ret);
+                return 0;
+            }
         }
     }
-    free(uid);
+
     LhsVar(1) = 0;
     PutLhsVar();