From 4d3bf1c446a7d1d2f85d368dfff70fcedfb5e045 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Mon, 28 Mar 2022 21:56:04 +0100 Subject: buflib: add comment in handle_alloc, remove a dead store It isn't obvious why the "handle->val = -1" at the end of handle_alloc is needed so add an explanatory comment. But "handle->val = 1" prior to calling handle_free is simply a dead store. Change-Id: I9ab4e96e87e940cfd1a2ed56f089287821669c73 --- firmware/buflib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/firmware/buflib.c b/firmware/buflib.c index 4b557eb59d..eccf8b057e 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c @@ -207,7 +207,11 @@ union buflib_data* handle_alloc(struct buflib_context *ctx) * and the found handle, therefore we can update first_free_handle */ ctx->first_free_handle = handle - 1; + /* We need to set the table entry to a non-NULL value to ensure that + * compactions triggered by an allocation do not compact the handle + * table and delete this handle. */ handle->val = -1; + return handle; } @@ -613,7 +617,6 @@ buffer_alloc: { goto buffer_alloc; } else { - handle->val=1; handle_free(ctx, handle); return -2; } -- cgit v1.2.3