harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r409622 - /incubator/harmony/enhanced/classlib/trunk/native-src/shared/launcher/main.c
Date Fri, 26 May 2006 10:17:39 GMT
Author: tellison
Date: Fri May 26 03:17:36 2006
New Revision: 409622

URL: http://svn.apache.org/viewvc?rev=409622&view=rev
Log:
Fix for HARMONY-510 (launcher can try to free argv element)

Modified:
    incubator/harmony/enhanced/classlib/trunk/native-src/shared/launcher/main.c

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/shared/launcher/main.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/native-src/shared/launcher/main.c?rev=409622&r1=409621&r2=409622&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/launcher/main.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/launcher/main.c Fri May 26
03:17:36 2006
@@ -106,6 +106,7 @@
   char **argv = args->argv;
   char *vmdll;
   char *mainClass = NULL;
+  char *mainClassAlloc = NULL;
   int isStandaloneJar = 0;
   int copyrightWritten = 0;
   int versionWritten = 0;
@@ -217,34 +218,39 @@
 	} /* end for-loop */
   } else {
 	/* We are a tool launcher: main class deduced from exe name */
-        mainClass = hymem_allocate_memory (
-          strlen(HY_TOOLS_PACKAGE) + strlen(exeBaseName) + strlen (HY_TOOLS_MAIN_TYPE) +
3);
-      if (mainClass == NULL) {
-          /* HYNLS_EXELIB_INTERNAL_VM_ERR_OUT_OF_MEMORY=Internal VM error: Out of memory\n
*/
-          PORTLIB->nls_printf (PORTLIB, HYNLS_ERROR, HYNLS_EXELIB_INTERNAL_VM_ERR_OUT_OF_MEMORY);
-          goto bail;
-        }
-	  strcpy (mainClass, HY_TOOLS_PACKAGE);
-          strcat (mainClass, ".");
-	  if (NULL == (str = strchr (exeBaseName, '.'))) {
-          strcat (mainClass, exeBaseName);
-	      strcat (mainClass, ".");
-	  } else {
-		  strncat (mainClass, exeBaseName, (str - exeBaseName + 1));
-	  }
-	  strcat (mainClass, HY_TOOLS_MAIN_TYPE);
+    mainClass = hymem_allocate_memory (
+      strlen(HY_TOOLS_PACKAGE) + strlen(exeBaseName) + strlen (HY_TOOLS_MAIN_TYPE) + 3);
+
+    if (mainClass == NULL) {
+      /* HYNLS_EXELIB_INTERNAL_VM_ERR_OUT_OF_MEMORY=Internal VM error: Out of memory\n */
+      PORTLIB->nls_printf (PORTLIB, HYNLS_ERROR, HYNLS_EXELIB_INTERNAL_VM_ERR_OUT_OF_MEMORY);
+      goto bail;
+	} else {
+      /* Remember that we malloc'ed this mainClass space so we can free it */
+      mainClassAlloc = mainClass;
+	}
 
-       /* Useful when debugging */
-       /* hytty_printf(PORTLIB, "Before...\n");
-        * for (i=0; i<argc; i++) {
-        *   hytty_printf(PORTLIB, "i=%d, v=%s\n", i, argv[i]);
-        * }
-        */ 
-
-	  /* Now ensure tools JAR is on classpath */
-	  augmentToolsArgs(args->portLibrary, &argc, &argv);
-	  classArg = arrangeToolsArgs(args->portLibrary, &argc, &argv, mainClass);
+    strcpy (mainClass, HY_TOOLS_PACKAGE);
+    strcat (mainClass, ".");
+    if (NULL == (str = strchr (exeBaseName, '.'))) {
+      strcat (mainClass, exeBaseName);
+      strcat (mainClass, ".");
+	} else {
+      strncat (mainClass, exeBaseName, (str - exeBaseName + 1));
 	}
+	strcat (mainClass, HY_TOOLS_MAIN_TYPE);
+
+    /* Useful when debugging */
+    /* hytty_printf(PORTLIB, "Before...\n");
+     * for (i=0; i<argc; i++) {
+     *   hytty_printf(PORTLIB, "i=%d, v=%s\n", i, argv[i]);
+     * }
+     */ 
+
+	/* Now ensure tools JAR is on classpath */
+	augmentToolsArgs(args->portLibrary, &argc, &argv);
+	classArg = arrangeToolsArgs(args->portLibrary, &argc, &argv, mainClass);
+  }
 
   /* Useful when debugging */
   /* hytty_printf(PORTLIB, "After...\n");
@@ -352,8 +358,8 @@
     hymem_free_memory (mainClass);
   }
 
-  if (mainClass) {
-    hymem_free_memory (mainClass);
+  if (mainClassAlloc) {
+    hymem_free_memory (mainClassAlloc);
   }
   if (propertiesFileName) {
     hymem_free_memory (propertiesFileName);



Mime
View raw message