Closed realvarx closed 1 month ago
I think I see see what is happening here
Since original_copy
is being freed, message_type
and message_body
are pointers to characters in the original_copy
string. Is that correct?
Assigned 2 SP
I think I see see what is happening here
Since
original_copy
is being freed,message_type
andmessage_body
are pointers to characters in theoriginal_copy
string. Is that correct?
Exactly
Fix for this in #400
The static
parse_message
function inmonitor.c
returnsmessage_type
andmessage_body
pointers that point to memory that is freed at the end of the function. This function creates a copy of the original parameter using strdup, which internally uses malloc to allocate memory. However, the function then frees this allocated memory (original_copy
) before returning, leavingmessage_type
andmessage_body
pointing to invalid memory.https://github.com/atsign-foundation/at_c/blob/aaf943db9c9de6b28b64ebdf9903928401ef793a/packages/atclient/src/monitor.c#L247
The solution would involve returning to the old approach (use
original
parameter, and free it outside of the method after doing memcpy of the type and body), or removing thefree(original_copy)
from the exit of the method (which could lead to a memory leak if not handled properly later).