Fix memory leak in event queue

If the event queue becomes full and an event needs to be discarded, the VM could leak memory because the arg type was still set to ARG_TYPE_OBJECT_NEW instead of ARG_TYPE_OBJECT.

This change moves the arg_deinit() until after the arg type is changed.
This commit is contained in:
Randy Scott 2023-05-26 19:48:53 -05:00 committed by Lyon
parent 35f518c90b
commit e747f7ac1d

View File

@ -215,14 +215,14 @@ PIKA_RES __eventListener_pushEvent(PikaEventListener* lisener,
pika_platform_panic_handle();
return PIKA_RES_ERR_OPERATION_FAILED;
#else
if (arg_getType(eventData) == ARG_TYPE_OBJECT_NEW) {
arg_setType(eventData, ARG_TYPE_OBJECT);
}
/* push to event_cq_buff */
if (_ecq_isFull(&g_PikaVMSignal.cq)) {
arg_deinit(eventData);
return PIKA_RES_ERR_SIGNAL_EVENT_FULL;
}
if (arg_getType(eventData) == ARG_TYPE_OBJECT_NEW) {
arg_setType(eventData, ARG_TYPE_OBJECT);
}
if (g_PikaVMSignal.cq.res[g_PikaVMSignal.cq.tail] != NULL) {
arg_deinit(g_PikaVMSignal.cq.res[g_PikaVMSignal.cq.tail]);
g_PikaVMSignal.cq.res[g_PikaVMSignal.cq.tail] = NULL;