aboutsummaryrefslogtreecommitdiff
path: root/src/net
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/net
parentc3fbb34a69de97540aec8fe2ff3884666925f25e (diff)
downloadjancity-83aabf01858e733338fb72f96b28d955b459bbb3.tar.gz
Avoid memory leak on failed realloc(3)
Diffstat (limited to 'src/net')
-rw-r--r--src/net/win9x/src/serial.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/net/win9x/src/serial.c b/src/net/win9x/src/serial.c
index 57d7261..cf77b9b 100644
--- a/src/net/win9x/src/serial.c
+++ b/src/net/win9x/src/serial.c
@@ -104,12 +104,16 @@ static int free_req(struct net_host_domain *const h, struct req *const r)
if (n)
{
- if (!(h->reqs = realloc(h->reqs, n * sizeof *h->reqs)))
+ struct req *const r = realloc(h->reqs, n * sizeof *h->reqs);
+
+ if (!r)
{
fprintf(stderr, "%s: realloc(3) failed: %s\n",
__func__, strerror(errno));
return -1;
}
+
+ h->reqs = r;
}
else
{
@@ -127,13 +131,18 @@ static int free_req(struct net_host_domain *const h, struct req *const r)
static struct req *alloc_req(struct net_host_domain *const h,
const void *const buf, const size_t n, const enum req_type t)
{
- if (!(h->reqs = realloc(h->reqs, (h->n_reqs + 1) * sizeof *h->reqs)))
+ struct req *const reqs = realloc(h->reqs,
+ (h->n_reqs + 1) * sizeof *h->reqs);
+
+ if (!reqs)
{
fprintf(stderr, "%s: realloc(3) failed: %s\n",
__func__, strerror(errno));
return NULL;
}
+ h->reqs = reqs;
+
struct req *const r = &h->reqs[h->n_reqs++];
*r = (const struct req)