From 20a203a200b26069fc1bbd7d276014b01bd884c0 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Sat, 13 May 2023 22:08:45 +0200 Subject: Ensure allocator return codes are properly negated --- src/strvec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/strvec.c b/src/strvec.c index dbc964e..13699a3 100644 --- a/src/strvec.c +++ b/src/strvec.c @@ -47,10 +47,14 @@ strvec_alloc(size_t cap, struct allocator *allocator, int *_rc) rc = _rc ? _rc : &stub; strvec = allocator->alloc(sizeof(struct strvec), rc); + if (!strvec && _rc) *rc = -*rc; if (!strvec) return NULL; *rc = strvec_init(strvec, cap, allocator); - if (*rc) return NULL; + if (*rc) { + allocator->free(strvec); + return NULL; + } return strvec; } @@ -71,8 +75,9 @@ strvec_free(struct strvec *strvec) rc = allocator->free(strvec); LIBSTRVEC_ABORT_ON_ALLOC(rc); + if (rc) return -rc; - return rc; + return 0; } int -- cgit v1.2.3-71-gd317