Skip to content

Commit 0edf6c1

Browse files
author
Alex Menkov
committed
8186825: some memory leak issues in the transport_startTransport
Reviewed-by: sspitsyn, phh
1 parent 9516e6d commit 0edf6c1

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/jdk.jdwp.agent/share/native/libjdwp/transport.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ typedef struct TransportInfo {
4949

5050
static struct jdwpTransportCallback callback = {jvmtiAllocate, jvmtiDeallocate};
5151

52+
static void freeTransportInfo(TransportInfo *info) {
53+
if (info) {
54+
jvmtiDeallocate(info->name);
55+
jvmtiDeallocate(info->address);
56+
jvmtiDeallocate(info->allowed_peers);
57+
jvmtiDeallocate(info);
58+
}
59+
}
60+
5261
/*
5362
* Print the last transport error
5463
*/
@@ -345,12 +354,14 @@ acceptThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
345354

346355
LOG_MISC(("Begin accept thread"));
347356

348-
info = (TransportInfo*)(void*)arg;
357+
info = (TransportInfo*)arg;
349358
t = info->transport;
350359
rc = (*t)->Accept(t, info->timeout, 0);
351360

352361
/* System property no longer needed */
353362
setTransportProperty(jni_env, NULL);
363+
/* TransportInfo data no longer needed */
364+
freeTransportInfo(info);
354365

355366
if (rc != JDWPTRANSPORT_ERROR_NONE) {
356367
/*
@@ -371,10 +382,14 @@ acceptThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
371382
static void JNICALL
372383
attachThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
373384
{
374-
TransportInfo *info = (TransportInfo*)(void*)arg;
385+
TransportInfo *info = (TransportInfo*)arg;
386+
jdwpTransportEnv *t = info->transport;
387+
388+
/* TransportInfo data no longer needed */
389+
freeTransportInfo(info);
375390

376391
LOG_MISC(("Begin attach thread"));
377-
connectionInitiated(info->transport);
392+
connectionInitiated(t);
378393
LOG_MISC(("End attach thread"));
379394
}
380395

@@ -484,7 +499,7 @@ transport_startTransport(jboolean isServer, char *name, char *address,
484499
if (info->transport == NULL) {
485500
serror = loadTransport(name, info);
486501
if (serror != JDWP_ERROR(NONE)) {
487-
jvmtiDeallocate(info);
502+
freeTransportInfo(info);
488503
return serror;
489504
}
490505
}
@@ -577,6 +592,9 @@ transport_startTransport(jboolean isServer, char *name, char *address,
577592
goto handleError;
578593
}
579594

595+
/* reset info - it will be deallocated by acceptThread */
596+
info = NULL;
597+
580598
launchCommand = debugInit_launchOnInit();
581599
if (launchCommand != NULL) {
582600
serror = launch(launchCommand, name, retAddress);
@@ -592,10 +610,7 @@ transport_startTransport(jboolean isServer, char *name, char *address,
592610
return JDWP_ERROR(NONE);
593611

594612
handleError:
595-
jvmtiDeallocate(info->name);
596-
jvmtiDeallocate(info->address);
597-
jvmtiDeallocate(info->allowed_peers);
598-
jvmtiDeallocate(info);
613+
freeTransportInfo(info);
599614
} else {
600615
/*
601616
* Note that we don't attempt to do a launch here. Launching
@@ -614,7 +629,7 @@ transport_startTransport(jboolean isServer, char *name, char *address,
614629
/* The name, address and allowed_peers fields in 'info'
615630
* are not allocated in the non-server case so
616631
* they do not need to be freed. */
617-
jvmtiDeallocate(info);
632+
freeTransportInfo(info);
618633
return serror;
619634
}
620635

0 commit comments

Comments
 (0)