Why is it?
The code hitting that error is here:
git.kernel.org/pub/scm/linux/…/subcmd-util.h
It looks fine to me.
What you are seeing is a warning that your compuler may have found a use-after-free bug, but I think this is a false positive. Your build is configured to turn this warning into a hard error.
How to fix it?
I think it will be difficult to know how to fix this without knowing more about your build setup. Are you passing any custom CFLAGS? What compiler and version are you using?
Also, here is someone asking about the same issue (in the same code) on Stack Exchange using GGC 12.1:
unix.stackexchange.com/…/linux-kernel-5-15-54-com…
This was the top result when Googling linux “-Werror=use-after-free”
.
I believe you can disable this warning in this file by adding a pragma after the includes (line 8):
#pragma GCC diagnostic ignored "-Wuse-after-free"
See stackoverflow.com/…/selectively-remove-a-warning-…
litchralee@sh.itjust.works 1 year ago
No objections to your answer to the OP’s question, but as a curiosity, I’m trying to figure out what the original xrealloc() function is trying to do.
So far as I can tell, it tries a normal realloc() with the requested size, but if that fails, trys again with size=1. But strangely, it that fails, trys using the requested size a second time. And if that still fails, tries once more with size=1.