hello,
i noticed there are a number of unchecked allocation calls, namely
entry.c-478- entry.c-479- if ((en->bufUsed + i) >= en->bufAlloced) { entry.c-480- en->bufAlloced += 20; entry.c:481: en->buf = realloc(en->buf, en->bufAlloced); entry.c-482- if (en->resultPtr) *en->resultPtr = en->buf; entry.c-483- memset(en->buf + en->bufAlloced - 20, 0, 20); entry.c-484- } -- form.c-599- form.c-600- if (form->numCompsAlloced == form->numComps) { form.c-601- form->numCompsAlloced += 5; form.c:602: form->elements = realloc(form->elements, form.c-603- sizeof(*(form->elements)) * form->numCompsAlloced); form.c-604- } form.c-605- -- form.c-897- struct form * form = co->data; form.c-898- form.c-899- form->numHotKeys++; form.c:900: form->hotKeys = realloc(form->hotKeys, sizeof(int) * form->numHotKeys); form.c-901- form->hotKeys[form->numHotKeys - 1] = key; form.c-902-} form.c-903- -- form.c-1241- break; form.c-1242- form.c-1243- if(i >= form->numFds) form.c:1244: form->fds = realloc(form->fds, (++form->numFds) * sizeof(*form->fds)); form.c-1245- form.c-1246- form->fds[i].fd = fd; form.c-1247- form->fds[i].flags = fdFlags;
there may be others, i only noticed these reallocs while reading some of the code. the api will probably need to be changed for these functions to return integer status instead of void.
form.c:1244: form->fds = realloc(form->fds, (++form->numFds) * sizeof(*form->fds));
fds is also leaked via newtFormWatchFd, it is never deallocated via newtFormDestroy.
I've pushed a fix for the leak of fds. Thanks.
I'm not sure about indicating the reallocation errors. Does that count as an ABI break?
i think it would. some options might be decorating with warn_unused_result https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute, or just using assert()s. allocation failure will likely result in the program terminating quickly anyway.
warn_unused_result