jynik / AddressSync

Ghidra Module: Allows external program to select current address via UDP message sent to port 1080

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resource Leak (Unclosed Socket)

astrelsky opened this issue · comments

I see you have suppressed the warning. You probably shouldn't although I'm not enough of a Java dev to know what the jvm will do with the unclosed socket.

You can move the catch block below to after the infinite while loop.

} catch (SocketException e) {
e.printStackTrace();
return;
}

After the catch block you can add the following to prevent the resource leak:

finally {
    if (sock != null) {
        sock.close();
    }
}

You could also use ByteBuffer to make it easier to receive the address by using asLongBuffer().get().

This is an an interesting plugin by the way.

Thanks @astrelsky, I'm surprised anyone has even seen this!

Might as well avoid the resource leak entirely, even if the socket lifetime should be as long as the plugin is loaded.

Good point about the ByteBuffer - added #2.

I have a tendency to search github for Ghidra and sort by recently updated. I try to avoid giving unsolicited advice or creating issues on things that may have been made for a single use purpose. I just found this interesting and couldn't help myself.