mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: hlua: fix ambiguous hlua usage in hlua_filter_delete()
In GH #2804, @Bbulatov reported that the result of hlua_stream_ctx_get() was used and de-referenced without checking if it's NULL in hlua_filter_delete() while other functions used to check for NULL before de-referencing it. In fact hlua_stream_ctx_get() can only return NULL if hlua_stream_ctx_prepare() failed or was not called on the current stream. Now because of the filter's API, since hlua_filter_delete() is mapped as detach method and hlua_filter_new() as attach method, and since hlua_filter_new() is responsible for calling hlua_stream_ctx_prepare(), there's no reason hlua_filter_delete() should be called if hlua_filter_new() failed or wasn't called. Thus we can assume that hlua can never be NULL in hlua_filter_delete(), so we add a BUG_ON() to ensure it is always the case and remove the ambiguity.
This commit is contained in:
parent
b167426b6b
commit
70b5cd6794
@ -12310,6 +12310,10 @@ static void hlua_filter_delete(struct stream *s, struct filter *filter)
|
|||||||
struct hlua_flt_ctx *flt_ctx = filter->ctx;
|
struct hlua_flt_ctx *flt_ctx = filter->ctx;
|
||||||
struct hlua *hlua = hlua_stream_ctx_get(s, flt_ctx->_hlua->state_id);
|
struct hlua *hlua = hlua_stream_ctx_get(s, flt_ctx->_hlua->state_id);
|
||||||
|
|
||||||
|
BUG_ON(!hlua); /* hlua_filter_new() is responsible for preparing
|
||||||
|
* hlua stream_ctx, thus hlua_stream_ctx_get() should
|
||||||
|
* not return NULL!
|
||||||
|
*/
|
||||||
hlua_lock(hlua);
|
hlua_lock(hlua);
|
||||||
hlua_unref(hlua->T, flt_ctx->ref);
|
hlua_unref(hlua->T, flt_ctx->ref);
|
||||||
hlua_unlock(hlua);
|
hlua_unlock(hlua);
|
||||||
|
Loading…
Reference in New Issue
Block a user