Skip to content

fix(network): close socket on every exit path in get_hash() (F-31, #117)#159

Merged
adequatelimited merged 1 commit intoaudit-fixesfrom
audit/F-31-get-hash-socket-leak
Apr 13, 2026
Merged

fix(network): close socket on every exit path in get_hash() (F-31, #117)#159
adequatelimited merged 1 commit intoaudit-fixesfrom
audit/F-31-get-hash-socket-leak

Conversation

@adequatelimited
Copy link
Copy Markdown
Collaborator

Summary

Closes #117 (F-31).

`get_hash()` leaked `np->sd` on `send_op()` or `recv_tx()` failure — both early returns skipped `sock_close()`. Under repeated peer probing failures (common with unreachable or misbehaving peers) this exhausts the process fd limit and prevents new outbound connections.

Restructured with a single `CLEANUP` label so every exit path (success, I/O failure, malformed response) closes the socket before returning. Matches the `DROP_CLEANUP` / `ERROR_CLEANUP` idiom used elsewhere in the codebase.

Test plan

  • Full build clean under `-Wall -Werror -Wextra -Wpedantic`.
  • Reviewed all three callers (`mochimo.c:434`, `mochimo.c:463`, `test/network-get-hash.c`); none read `np->sd` after the call.

get_hash() leaked np->sd on send_op() or recv_tx() failure: both early
returns skipped sock_close(). Under repeated peer probing failures
(common on unreachable or misbehaving peers) this exhausts the fd
limit and prevents new outbound connections.

Restructure with a single CLEANUP label so every exit path -- success,
I/O failure, and malformed response -- closes the socket before
returning. Matches the DROP_CLEANUP/ERROR_CLEANUP idiom used elsewhere
in the codebase.
@adequatelimited adequatelimited merged commit 2cad021 into audit-fixes Apr 13, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant