bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak in error.c


From: Bruno Haible
Subject: Re: Memory leak in error.c
Date: Thu, 01 Jun 2017 22:10:39 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-78-generic; KDE/5.18.0; x86_64; ; )

Hi John,

> 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;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]