From c66121915ebd38eb91cd71a5b81b51acb29c89b6 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 16 Jul 2021 17:37:51 -0700 Subject: [PATCH] remove return value from vmfree MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There is no reasonable action for a caller to take based on a deallocation request failing. This is inline with ISO C’s `free` having no return value. --- lib/vmalloc/test.c | 24 +++++++++--------------- lib/vmalloc/vmalloc.c | 7 +++---- lib/vmalloc/vmalloc.h | 3 +-- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/vmalloc/test.c b/lib/vmalloc/test.c index baf5a5568..73352d917 100644 --- a/lib/vmalloc/test.c +++ b/lib/vmalloc/test.c @@ -95,18 +95,15 @@ static void test_lifecycle(void) { assert(v->size == allocations_len); // free a few allocations out of order from that in which we allocated - int r = vmfree(v, p[3]); - assert(r == 0); - r = vmfree(v, p[6]); - assert(r == 0); - r = vmfree(v, p[5]); - assert(r == 0); + vmfree(v, p[3]); + vmfree(v, p[6]); + vmfree(v, p[5]); // the allocator should have correctly stopped tracking those pointers assert(v->size == allocations_len - 3); // free the rest of the allocations in one sweep - r = vmclear(v); + int r = vmclear(v); assert(r == 0); /* the allocator should have dropped all pointers it was tracking */ @@ -164,8 +161,7 @@ static void test_resize(void) { } // discard this - int r = vmfree(v, p); - assert(r == 0); + vmfree(v, p); // get a new pointer p = vmalloc(v, s); @@ -204,7 +200,7 @@ static void test_resize(void) { } // clean up - r = vmclose(v); + int r = vmclose(v); assert(r == 0); } @@ -239,10 +235,8 @@ static void test_strdup(void) { assert(strcmp(s, t) == 0); // discard these strings - int r = vmfree(v, s); - assert(r == 0); - r = vmfree(v, t); - assert(r == 0); + vmfree(v, s); + vmfree(v, t); /* vmstrdup does not assume the input string is mutable, so lets pass it a * non-writable string @@ -255,7 +249,7 @@ static void test_strdup(void) { assert(strcmp(sc, t) == 0); // clean up - r = vmclose(v); + int r = vmclose(v); assert(r == 0); } diff --git a/lib/vmalloc/vmalloc.c b/lib/vmalloc/vmalloc.c index 3134ab294..2f203006e 100644 --- a/lib/vmalloc/vmalloc.c +++ b/lib/vmalloc/vmalloc.c @@ -54,10 +54,10 @@ void *vmalloc(Vmalloc_t *vm, size_t size) { return p; } -int vmfree(Vmalloc_t *vm, void *data) { +void vmfree(Vmalloc_t *vm, void *data) { if (!data) { // ANSI-ism - return 0; + return; } // find the pointer we previously allocated @@ -72,12 +72,11 @@ int vmfree(Vmalloc_t *vm, void *data) { // give this back to the underlying allocator free(data); - return 0; + return; } } // we did not find this pointer; free() of something we did not allocate - return -1; } void *vmresize(Vmalloc_t *vm, void *data, size_t size) { diff --git a/lib/vmalloc/vmalloc.h b/lib/vmalloc/vmalloc.h index a2ee07d7c..af5b94b5c 100644 --- a/lib/vmalloc/vmalloc.h +++ b/lib/vmalloc/vmalloc.h @@ -54,9 +54,8 @@ void *vmresize(Vmalloc_t *vm, void *data, size_t size); * * @param vm Region the pointer was originally allocated from * @param data The pointer originally received from vmalloc - * @returns 0 on success */ -int vmfree(Vmalloc_t *vm, void *data); +void vmfree(Vmalloc_t *vm, void *data); extern char *vmstrdup(Vmalloc_t *, const char *); -- 2.49.0