Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make memory leak in xRealloc explicit
There is an edge case in xRealloc upon failure to realloc memory that manifests when the memory area pointed to by ptr contains pointers. As the structure of ptr is opaque to xRealloc there's no chance for properly releasing the memory for those indirect pointers. The best we could do is release ptr itself, leaving behind an indirect leak of those pointers inside the memory pointed to by ptr. This memory leak is picked up by analyzers like deepcode and GCC 14's -fanalyzer, which causes a lengthy, hard-to-parse diagnostic. Leaving the memory allocated and failing on this code path is properly ignored though (at least with GCC 14). A better solution thus is to keep ptr untouched and instead leak the whole block which avoids this diagnostic on indirectly leaked memory which is free'd by bailing shortly after anyway. This is not a fix, neither was the code we had before. This commit mainly documents an edge case and tries to avoid some hard-to-understand (but unavoidable) leak by making it more blatantly obvious in the used tooling.
- Loading branch information