[PATCH resend2] 8145278: Fix memory leak in splitPathList
serguei.spitsyn at oracle.com
serguei.spitsyn at oracle.com
Tue Apr 12 20:07:42 UTC 2016
Hi Alex,
The fix looks good.
Could you tell why this is important to you, what is the motivation?
Do you really observe this problem, or it is based on a static analysis?
Thanks,
Serguei
On 4/12/16 12: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