8145278: Fix memory leak in splitPathList
authorahenrie
Tue, 17 Nov 2015 23:10:30 -0700
changeset 38330 4dd3c45e0a16
parent 37533 3b9eb1a3a4ee
child 38331 b573786bd981
child 38332 95dd1e0f418f
child 38337 8aea60827524
8145278: Fix memory leak in splitPathList Reviewed-by: sspitsyn, dsamersoff, dcubed
jdk/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
--- a/jdk/src/java.instrument/share/native/libinstrument/InvocationAdapter.c	Thu Apr 14 19:55:41 2016 -0700
+++ b/jdk/src/java.instrument/share/native/libinstrument/InvocationAdapter.c	Tue Nov 17 23:10:30 2015 -0700
@@ -518,18 +518,22 @@
 splitPathList(const char* str, int* pathCount, char*** paths) {
     int count = 0;
     char** segments = NULL;
+    char** new_segments;
     char* c = (char*) str;
     while (*c != '\0') {
         while (*c == ' ') c++;          /* skip leading spaces */
         if (*c == '\0') {
             break;
         }
-        if (segments == NULL) {
-            segments = (char**)malloc( sizeof(char**) );
-        } else {
-            segments = (char**)realloc( segments, (count+1)*sizeof(char**) );
+        new_segments = (char**)realloc(segments, (count+1)*sizeof(char*));
+        if (new_segments == NULL) {
+            jplis_assert(0);
+            free(segments);
+            count = 0;
+            segments = NULL;
+            break;
         }
-        jplis_assert(segments != (char**)NULL);
+        segments = new_segments;
         segments[count++] = c;
         c = strchr(c, ' ');
         if (c == NULL) {