Fix #332: prevent mutex leak in ipv4_connect when LocalIP is already set #401
Reference in New Issue
Block a user
Delete Branch "jasonL/kolibrios:fix/ipv4-connect-mutex-leak"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #332.
This fixes a mutex leak in
ipv4_connectwhenIP_SOCKET.LocalIPis already set.The old code used:
after checking
LocalIP.In
ipv4_connect, that anonymous forward jump could leave the normal tail path and skip theRemoteIPupdate together withmutex_unlock, so repeatedconnectcalls on the same socket could leaveSOCKET.mutexlocked.The fix is to replace that anonymous jump with an explicit local label, so both
LocalIP == 0andLocalIP != 0paths continue through the same cleanup flow:Verified with the reproducer attached to #332 (
sock_dedlock.ASM), which callsconnectrepeatedly on the same socket.On the baseline build, the first
connectreturned, the next call left the socket locked, and the following call blocked on the same mutex.On the patched build, repeated
connectcalls returned normally and no stuck mutex was observed.I also checked this with temporary debug instrumentation in
ipv4_connect. The baseline trace wasELZRUX, thenEL, thenE; the patched trace wasELZRUX, thenELNRUX, thenELNRUX.Here
Emeans function entry,Lmeansmutex_lockreturned,ZmeansLocalIP == 0,NmeansLocalIP != 0,RmeansRemoteIPwas written,Umeansmutex_unlock, andXmeans return.This change only fixes the lock leak in
ipv4_connect. It does not change the existingFIXME: use correct local IPbehavior.