[PATCH] 8145278: Fix memory leak in splitPathList
Alex Henrie
alexhenrie24 at gmail.com
Tue Feb 9 18:29:37 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 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++;
}
More information about the serviceability-dev
mailing list