RFR: JDK-8261601: free memory in early return in Java_sun_nio_ch_sctp_SctpChannelImpl_receive0

Alan Bateman alanb at openjdk.java.net
Sat Feb 13 17:30:39 UTC 2021


On Fri, 12 Feb 2021 08:50:14 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

> Btw. while adjusting Java_sun_nio_ch_sctp_SctpChannelImpl_receive0 , I started to wonder what happens to the allocated memory in the same file in handleSendFailed ( if ((addressP = malloc(dataLength)) == NULL) ) in early return cases incl. the CHECK_NULL , is there some deallocation missing there too ?

Yes, the error paths in handleSendFailed should be looked at. If NewDirectByteBuffer or recvmsg fails then addressP needs to be freed. Furthermore, if the NewObject fails and bufferObj != NULL then the memory for the direct buffer will need to be freed too (as JNI NewDirectByteBuffer does not setup a cleaner).

-------------

PR: https://git.openjdk.java.net/jdk/pull/2540


More information about the net-dev mailing list