[PATCH resend] 8145278: Fix memory leak in splitPathList

Alex Henrie alexhenrie24 at gmail.com
Mon Apr 4 16:50:28 UTC 2016


# HG changeset patch
# User Alex Henrie <alexhenrie24 at gmail.com>
# Date 1447827030 25200
#      Tue Nov 17 23:10:30 2015 -0700
# Node ID 8021a03115817aa9c641333848e2f483516f06a7
# Parent  0007e5d265a849b73114c98b3d4f55dde83a57ea
8145278: Fix memory leak in splitPathList

diff --git a/src/java.instrument/share/native/libinstrument/InvocationAdapter.c b/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
--- a/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
+++ b/src/java.instrument/share/native/libinstrument/InvocationAdapter.c
@@ -513,28 +513,32 @@ eventHandlerClassFileLoadHook(  jvmtiEnv
  * The attribute value is in UTF8 but cannot contain NUL. Also non US-ASCII
  * characters must be escaped (URI syntax) so safe to iterate through the
  * value as a C string.
  */
 static void
 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) {
             break;
         }
         *c = '\0';
         c++;
     }


More information about the serviceability-dev mailing list