aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-04-30 17:07:00 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-04-30 17:08:04 +0200
commit83aabf01858e733338fb72f96b28d955b459bbb3 (patch)
treec1d499969e4a9c20759a44edb806725742a11814 /src/transport
parentc3fbb34a69de97540aec8fe2ff3884666925f25e (diff)
downloadjancity-83aabf01858e733338fb72f96b28d955b459bbb3.tar.gz
Avoid memory leak on failed realloc(3)
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/src/heap.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/transport/src/heap.c b/src/transport/src/heap.c
index bcf0d6f..221c203 100644
--- a/src/transport/src/heap.c
+++ b/src/transport/src/heap.c
@@ -55,11 +55,13 @@ union transport_packet *transport_packet_alloc(const enum transport_packet_type
int transport_append(struct transport_handle *const h,
union transport_packet *const p)
{
- h->packets = realloc(h->packets, (h->n_packets + 1) * sizeof *h->packets);
+ union transport_packet **const packets = realloc(h->packets,
+ (h->n_packets + 1) * sizeof *h->packets);
- if (!h->packets)
+ if (!packets)
return -1;
+ h->packets = packets;
h->packets[h->n_packets++] = p;
return 0;
}