
On 04.09.2013 22:18, Eric Blake wrote:
On 09/04/2013 02:03 PM, Jim Fehlig wrote:
Yeah, good question. I found a few occurrences of regcomp() and friends throughout the sources and most seem to do regfree() even when regcomp() fails. The man page is not very clear, but the notes on regfree() suggest it is not necessary
POSIX Pattern Buffer Freeing Supplying regfree() with a precompiled pattern buffer, preg will free the memory allocated to the pattern buffer by the compiling process, regcomp().
But does the pattern buffer contain any allocated memory when regcomp() fails? The notes on regcomp() are not clear about this.
Thankfully, we can read the source :)
In glibc, regcomp assigns into preg, but is careful to undo any allocation on failure; it is also careful to make regfree() a no-op on an already-freed buffer (whether by calling regfree() twice in a row, or using it on preg after a failed regcomp). Gnulib copies this behavior. But it is not universally standard:
Question then is: if regcomp(®, ...) fails, reg == NULL, right? But passing the @reg to regerror: regerror(errcode, ®, ...) doesn't make much sense then. It can make, if regcomp would free all mem allocated, but set @reg to different values (each of them representing different cause of error). If that is the case, <irony>this is what I call the design!</irony> Michal