From 63bbb9320d101f17e1dc75d35746f5cdff285668 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 5 Nov 2026 16:34:50 +0100 Subject: Initialise memory before it's pointers are used in case of a failed allocation --- src/trackerlogic.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/trackerlogic.c b/src/trackerlogic.c index d25ddac..7e8d969 100644 --- a/src/trackerlogic.c +++ b/src/trackerlogic.c @@ -65,14 +65,12 @@ void add_torrent_from_saved_state(ot_hash const hash, ot_time age, size_t down_c memset(torrent, 0, sizeof(ot_torrent)); memcpy(torrent->hash, hash, sizeof(ot_hash)); - if (!(torrent->peer_list6 = malloc(sizeof(ot_peerlist))) || !(torrent->peer_list4 = malloc(sizeof(ot_peerlist)))) { + if (!(torrent->peer_list6 = calloc(1, sizeof(ot_peerlist))) || !(torrent->peer_list4 = calloc(1, sizeof(ot_peerlist)))) { vector_remove_torrent(torrents_list, torrent); mutex_bucket_unlock_by_hash(hash, 0); return; } - memset(torrent->peer_list6, 0, sizeof(ot_peerlist)); - memset(torrent->peer_list4, 0, sizeof(ot_peerlist)); torrent->peer_list6->base = time_now_minutes() - age; torrent->peer_list4->base = time_now_minutes() - age; torrent->peer_list6->down_count = down_count; @@ -110,14 +108,12 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru memset(torrent, 0, sizeof(ot_torrent)); memcpy(torrent->hash, *ws->hash, sizeof(ot_hash)); - if (!(torrent->peer_list6 = malloc(sizeof(ot_peerlist))) || !(torrent->peer_list4 = malloc(sizeof(ot_peerlist)))) { + if (!(torrent->peer_list6 = calloc(1, sizeof(ot_peerlist))) || !(torrent->peer_list4 = calloc(1, sizeof(ot_peerlist)))) { vector_remove_torrent(torrents_list, torrent); mutex_bucket_unlock_by_hash(*ws->hash, 0); return 0; } - memset(torrent->peer_list6, 0, sizeof(ot_peerlist)); - memset(torrent->peer_list4, 0, sizeof(ot_peerlist)); delta_torrentcount = 1; } else clean_single_torrent(torrent); -- cgit v1.3