[PATCH resend2] 8145278: Fix memory leak in splitPathList
Daniel D. Daugherty
daniel.daugherty at oracle.com
Tue Apr 12 21:34:40 UTC 2016
I'm also good with the fix. At this point, I think everyone who
has commented on this fix previously has chimed in...
Dan
On 4/12/16 3:12 PM, Dmitry Samersoff wrote:
> Alex,
>
> The fix looks good for me.
>
> -Dmitry
>
>
> On 2016-04-12 22:28, Alex Henrie wrote:
>> # HG changeset patch
>> # User Alex Henrie <alexhenrie24 at gmail.com>
>> # Date 1447827030 25200
>> # Tue Nov 17 23:10:30 2015 -0700
>> # Node ID 66c6fa3b2280afa12a2d51ea668b6a781b5744b5
>> # Parent 1f8c4b1a301c989dc299cad63dbc530b1de3ed70
>> 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