heatgun
heatgun copied to clipboard
A potential problem
I want to reuse the code of function addModeChangedCallback, (https://github.com/PTDreamer/heatgun/blob/167bac1dbc2e882feef456b81d40e7900f00f8f1/Src/gun.c#LL124C27-L124C27). However, I find that there is potential problem:
void addModeChangedCallback(currentModeChanged callback) {
currentModeChangedCallbackStruct_t *s = malloc(sizeof(currentModeChangedCallbackStruct_t));
s->callback = callback;
s->next = NULL;
...
}
In function addModeChangedCallback, the program uses malloc to allocate memory space for s, but does not judge the allocation result. When allocation fails, s is null, a null-pointer-dereference happens here, that is, s->callback (null->callback) .