[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-serviceability-dev
Subject:    [PATCH] 8145278: Fix memory leak in splitPathList
From:       Alex Henrie <alexhenrie24 () gmail ! com>
Date:       2016-02-09 18:29:37
Message-ID: 66ac6f9c95653631b99b.1455042577 () localhost ! localdomain
[Download RAW message or body]

# HG changeset patch
# User Alex Henrie <alexhenrie24@gmail.com>
# Date 1447827030 25200
#      Tue Nov 17 23:10:30 2015 -0700
# Node ID 66ac6f9c95653631b99b69d97a45cbbd82684778
# Parent  ab2ab8a6f54c9f2591fe3b035b5b09d5ada66106
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++;
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic