From a4904ed2e437275bfd92828ad09fbb677d7225d1 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 24 Oct 2026 17:32:54 +0200 Subject: free_peerlist now checks peer_list for NULL, so on alloc failure we don't dereference NULL --- ot_vector.c | 2 -- trackerlogic.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ot_vector.c b/ot_vector.c index e3c3d3f..c4cd171 100644 --- a/ot_vector.c +++ b/ot_vector.c @@ -156,8 +156,6 @@ void vector_remove_torrent(ot_vector *vector, ot_torrent *match) { if (!vector->size) return; - /* If this is being called after a unsuccessful malloc() for peer_list - in add_peer_to_torrent, match->peer_list actually might be NULL */ free_peerlist(match->peer_list6); free_peerlist(match->peer_list4); diff --git a/trackerlogic.c b/trackerlogic.c index f5e3dc0..db1d787 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -31,8 +31,8 @@ /* Forward declaration */ size_t return_peers_for_torrent(struct ot_workstruct *ws, ot_torrent *torrent, size_t amount, char *reply, PROTO_FLAG proto); -void free_peerlist(ot_peerlist *peer_list) { - if (peer_list->peers.data) { +void free_peerlist(ot_peerlist *peer_list) { + if (peer_list && peer_list->peers.data) { if (OT_PEERLIST_HASBUCKETS(peer_list)) vector_clean_list((ot_vector *)peer_list->peers.data, peer_list->peers.size); else -- cgit v1.3