Hi Matthias, okay, if it is simplicity you are after, you could completely remove the truncation handling too, since a buffer with 100 bytes leaves you 29 bytes for 29 digits; that is more than enough to display an int even if it were 64bit (uint64 max = 18,446,744,073,709,551,615, 20 digits).
But I leave it up to you. The important thing is that the memory leak gets fixed. Reviewed from my end. Thanks, Thomas On Wed, Jun 20, 2018 at 11:05 AM, Baesken, Matthias <matthias.baes...@sap.com> wrote: > Hi Thomas, I considered it but then I thought that the coding gets a bit > simpler with a fix buffer . > > Best regards, Matthias > >> -----Original Message----- >> From: Thomas Stüfe [mailto:thomas.stu...@gmail.com] >> Sent: Mittwoch, 20. Juni 2018 10:26 >> To: Baesken, Matthias <matthias.baes...@sap.com> >> Cc: net-dev@openjdk.java.net >> Subject: Re: RFR: 8205342: windows : potential memleaks in getAdapter(s) in >> NetworkInterface_winXP.c >> >> Hi Matthias, >> >> thanks, good catch about the leak. >> >> But could you not just simply free the error_msg_buf after the call to >> JNU_ThrowByName? >> >> JNU_ThrowByName copies the message string, so no need to keep it alive >> afterwards: >> >> diff -r e810abb27deb >> src/java.base/windows/native/libnet/NetworkInterface_winXP.c >> --- a/src/java.base/windows/native/libnet/NetworkInterface_winXP.c >> Wed Jun 20 06:51:39 2018 +0200 >> +++ b/src/java.base/windows/native/libnet/NetworkInterface_winXP.c >> Wed Jun 20 10:21:57 2018 +0200 >> @@ -138,6 +138,7 @@ >> JNU_ThrowByName(env, "java/lang/Error", >> "IP Helper Library GetAdaptersAddresses >> function failure"); >> } >> + free(error_msg_buf); >> } else { >> JNU_ThrowByName(env, "java/lang/Error", >> "IP Helper Library GetAdaptersAddresses function >> failed"); >> >> Thanks, Thomas >> >> >> >> On Wed, Jun 20, 2018 at 10:07 AM, Baesken, Matthias >> <matthias.baes...@sap.com> wrote: >> > Hello . Please review this small fix that fixes potential memory leaks >> > in getAdapter(s) in NetworkInterface_winXP.c and simplifies the coding a >> > bit too . >> > >> > Currently when generating error messages , some memory is malloc-ed >> > for the error messages , but not always freed . >> > >> > >> > >> > >> > >> > Bug: >> > >> > >> > >> > https://bugs.openjdk.java.net/browse/JDK-8205342 >> > >> > >> > >> > webrev : >> > >> > >> > >> > http://cr.openjdk.java.net/~mbaesken/webrevs/8205342/ >> > >> > >> > >> > >> > >> > Thanks, Matthias >> > >> > >> > >> >