[kaffe] kaffe -jar fails when environment variable CLASSPATH is set

Ito Kazumitsu ito.kazumitsu at hidec.co.jp
Mon Jun 6 21:08:27 PDT 2005


> Kaffe invoked with -jar option failes if the environment variable
                                 fails
> CLASSPATH is set.  Please see the following test case.

How about this?

--- kaffe/kaffe/main.c.orig	Tue May 31 06:16:02 2005
+++ kaffe/kaffe/main.c	Tue Jun  7 13:00:52 2005
@@ -130,6 +130,17 @@
 		}
 #endif
 	}
+	/* classpath may be changed later, so we copy it to a newly allocated
+	   area so that the memory can be freed. */
+	if (cp != NULL) {
+		char* newcp;
+		if ((newcp = malloc(strlen(cp) + 1)) == NULL) {
+			fprintf(stderr,  _("Error: out of memory.\n"));
+			exit(1);
+		}
+		strcpy(newcp, cp);
+		cp = newcp;
+	}
 	vmargs.classpath = cp;
 
         cp = getenv(LIBRARYPATH1);
@@ -499,15 +510,17 @@
 				+ strlen(argv[i])
 				+ 1;
 
-			/* Get longer buffer FIXME:  free the old one */
+			/* Get longer buffer */
 			if ((newcpath = malloc(cpathlength)) == NULL) {
 				fprintf(stderr,  _("Error: out of memory.\n"));
 				exit(1);
 			}
 
 			/* Construct new classpath */
-			if( vmargs.classpath != 0 )
+			if( vmargs.classpath != 0 ) {
 			  	strcpy(newcpath, vmargs.classpath);
+				free(vmargs.classpath);
+			}
 			else
 				newcpath[0] = '\0';
 			strcat(newcpath, path_separator);




More information about the kaffe mailing list