Discussion:
Memory leak in error.c
Add Reply
John Darrington
2017-06-01 19:13:00 UTC
Reply
Permalink
Raw Message
In lib/error.c the function void error (int status, int errnum, const char *message, ...)

has a va_start but no corresponding va_end.

This will leak memory.

J'
--
Avoid eavesdropping. Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.
Bruno Haible
2017-06-01 20:10:39 UTC
Reply
Permalink
Raw Message
Hi John,
Post by John Darrington
In lib/error.c the function void error (int status, int errnum, const char *message, ...)
has a va_start but no corresponding va_end.
This will leak memory.
The call to va_end occurs inside the 'error_tail' function, which 'error' invokes
after va_start.

It is surely a POSIX violation, because POSIX [1] says
"Each invocation of the va_start() and va_copy() macros shall be matched by a
corresponding invocation of the va_end() macro in the same function."
^^^^^^^^^^^^^^^^^^^^

However, I don't think that it will "leak memory", because
- If va_start was to allocate memory, it would have to provide an error code.
But no, va_start always returns successfully.
- The GCC implementation of __builtin_va_end expands to empty. [2]

Bruno

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdarg.h.html
[2] gcc-7.1.0 source code:

/* Expand EXP, a call to __builtin_va_end. */

static rtx
expand_builtin_va_end (tree exp)
{
tree valist = CALL_EXPR_ARG (exp, 0);

/* Evaluate for side effects, if needed. I hate macros that don't
do that. */
if (TREE_SIDE_EFFECTS (valist))
expand_expr (valist, const0_rtx, VOIDmode, EXPAND_NORMAL);

return const0_rtx;
}
Paul Eggert
2017-06-01 21:13:15 UTC
Reply
Permalink
Raw Message
Post by Bruno Haible
The call to va_end occurs inside the 'error_tail' function, which 'error' invokes
after va_start.
It is surely a POSIX violation
Yes, thanks for pointing it out. I installed the attached.

Loading...