@@ -49,6 +49,15 @@ typedef struct TransportInfo {
49
49
50
50
static struct jdwpTransportCallback callback = {jvmtiAllocate , jvmtiDeallocate };
51
51
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
+
52
61
/*
53
62
* Print the last transport error
54
63
*/
@@ -345,12 +354,14 @@ acceptThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
345
354
346
355
LOG_MISC (("Begin accept thread" ));
347
356
348
- info = (TransportInfo * )( void * ) arg ;
357
+ info = (TransportInfo * )arg ;
349
358
t = info -> transport ;
350
359
rc = (* t )-> Accept (t , info -> timeout , 0 );
351
360
352
361
/* System property no longer needed */
353
362
setTransportProperty (jni_env , NULL );
363
+ /* TransportInfo data no longer needed */
364
+ freeTransportInfo (info );
354
365
355
366
if (rc != JDWPTRANSPORT_ERROR_NONE ) {
356
367
/*
@@ -371,10 +382,14 @@ acceptThread(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
371
382
static void JNICALL
372
383
attachThread (jvmtiEnv * jvmti_env , JNIEnv * jni_env , void * arg )
373
384
{
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 );
375
390
376
391
LOG_MISC (("Begin attach thread" ));
377
- connectionInitiated (info -> transport );
392
+ connectionInitiated (t );
378
393
LOG_MISC (("End attach thread" ));
379
394
}
380
395
@@ -484,7 +499,7 @@ transport_startTransport(jboolean isServer, char *name, char *address,
484
499
if (info -> transport == NULL ) {
485
500
serror = loadTransport (name , info );
486
501
if (serror != JDWP_ERROR (NONE )) {
487
- jvmtiDeallocate (info );
502
+ freeTransportInfo (info );
488
503
return serror ;
489
504
}
490
505
}
@@ -577,6 +592,9 @@ transport_startTransport(jboolean isServer, char *name, char *address,
577
592
goto handleError ;
578
593
}
579
594
595
+ /* reset info - it will be deallocated by acceptThread */
596
+ info = NULL ;
597
+
580
598
launchCommand = debugInit_launchOnInit ();
581
599
if (launchCommand != NULL ) {
582
600
serror = launch (launchCommand , name , retAddress );
@@ -592,10 +610,7 @@ transport_startTransport(jboolean isServer, char *name, char *address,
592
610
return JDWP_ERROR (NONE );
593
611
594
612
handleError :
595
- jvmtiDeallocate (info -> name );
596
- jvmtiDeallocate (info -> address );
597
- jvmtiDeallocate (info -> allowed_peers );
598
- jvmtiDeallocate (info );
613
+ freeTransportInfo (info );
599
614
} else {
600
615
/*
601
616
* Note that we don't attempt to do a launch here. Launching
@@ -614,7 +629,7 @@ transport_startTransport(jboolean isServer, char *name, char *address,
614
629
/* The name, address and allowed_peers fields in 'info'
615
630
* are not allocated in the non-server case so
616
631
* they do not need to be freed. */
617
- jvmtiDeallocate (info );
632
+ freeTransportInfo (info );
618
633
return serror ;
619
634
}
620
635
0 commit comments