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
This commit is contained in:
Aidan MacDonald 2022-03-28 21:56:04 +01:00
parent 840f6b79c7
commit 4d3bf1c446

View file

@ -207,7 +207,11 @@ union buflib_data* handle_alloc(struct buflib_context *ctx)
* and the found handle, therefore we can update first_free_handle */ * and the found handle, therefore we can update first_free_handle */
ctx->first_free_handle = handle - 1; 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; handle->val = -1;
return handle; return handle;
} }
@ -613,7 +617,6 @@ buffer_alloc:
{ {
goto buffer_alloc; goto buffer_alloc;
} else { } else {
handle->val=1;
handle_free(ctx, handle); handle_free(ctx, handle);
return -2; return -2;
} }