From 0b166331573af4ba50f1900fef71060de881174c Mon Sep 17 00:00:00 2001 From: Alberto Leiva Popper Date: Fri, 24 Oct 2025 16:05:50 -0600 Subject: [PATCH] Fix memory leaks --- src/asn1/asn1c/INTEGER.c | 24 ++++++++++++++++++++++++ src/asn1/asn1c/INTEGER.h | 2 ++ src/cache.c | 1 + src/rrdp.c | 5 ++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/asn1/asn1c/INTEGER.c b/src/asn1/asn1c/INTEGER.c index 01e5202e..9fc43a80 100644 --- a/src/asn1/asn1c/INTEGER.c +++ b/src/asn1/asn1c/INTEGER.c @@ -790,6 +790,30 @@ INTEGER_move(INTEGER_t *to, INTEGER_t *from) memset(from, 0, sizeof(*from)); } +void +INTEGER_copy(INTEGER_t *to, INTEGER_t *from) +{ + to->size = from->size; + to->buf = pmalloc(to->size); + memcpy(to->buf, from->buf, to->size); +} + +static int +just_print(const void *buffer, size_t size, void *pfx) +{ + pr_trc("%s: %.*s", (char const *)pfx, (int)size, buffer); + return 0; +} + +void +INTEGER_trc(char const *pfx, INTEGER_t *st) +{ + if (st != NULL) + INTEGER_print(&asn_DEF_INTEGER, st, 2, just_print, (void *)pfx); + else + pr_trc("%s: NULL", pfx); +} + void INTEGER_cleanup(INTEGER_t *st) { diff --git a/src/asn1/asn1c/INTEGER.h b/src/asn1/asn1c/INTEGER.h index 68e9027c..a85ec1c7 100644 --- a/src/asn1/asn1c/INTEGER.h +++ b/src/asn1/asn1c/INTEGER.h @@ -93,6 +93,8 @@ const asn_INTEGER_enum_map_t *INTEGER_map_value2enum( int INTEGER_cmp(INTEGER_t const *, INTEGER_t const *); void INTEGER_move(INTEGER_t *, INTEGER_t *); +void INTEGER_copy(INTEGER_t *, INTEGER_t *); +void INTEGER_trc(char const *, INTEGER_t *); void INTEGER_cleanup(INTEGER_t *); #endif /* _INTEGER_H_ */ diff --git a/src/cache.c b/src/cache.c index 34f5e68b..bcd6d76c 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1305,6 +1305,7 @@ commit_rpp(struct cache_commit *commit, struct cache_node *fb) char const *dst; array_index i; + INTEGER_cleanup(&fb->mft.num); INTEGER_move(&fb->mft.num, &commit->mft.num); fb->mft.update = commit->mft.update; diff --git a/src/rrdp.c b/src/rrdp.c index 52ca117c..e6b39577 100644 --- a/src/rrdp.c +++ b/src/rrdp.c @@ -1148,9 +1148,11 @@ update_notif(struct rrdp_state *old, struct update_notification *new) struct rrdp_hash *hash; diff_bn = BN_create(); - if (!BN_sub(diff_bn, new->session.serial.num, old->session.serial.num)) + if (!BN_sub(diff_bn, new->session.serial.num, old->session.serial.num)) { + BN_free(diff_bn); return pr_crypto_err("OUCH! libcrypto cannot subtract %s - %s", new->session.serial.str, old->session.serial.str); + } if (BN_is_negative(diff_bn)) /* The validation was the BN_cmp() in the caller. */ pr_panic("%s - %s < 0 despite validations.", @@ -1161,6 +1163,7 @@ update_notif(struct rrdp_state *old, struct update_notification *new) /* Should be <= because it was already compared to the delta threshold. */ pr_panic("%lu > %zu despite validations.", diff, new->deltas.len); + BN_free(diff_bn); BN_free(old->session.serial.num); free(old->session.serial.str); -- 2.47.3