This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Cleanup: don't call free(NULL) unnecessarily


Hi!

On Tue, 05 Mar 2013 11:18:01 -0800, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:
> This patch eliminates calls to free(NULL) from within vfprintf.
> 
> This is desirable because e.g. fprintf(stderr, ...) is often called from
> signal handlers, and while technically illegal, this tends to work.
> 
> Glibc free(NULL) also works in signal context, but end user could supply
> his own malloc/free, which may not.
> 
> The same check was already done on e.g. line 1648.

> --- a/stdio-common/vfprintf.c
> +++ b/stdio-common/vfprintf.c
> @@ -1691,7 +1691,8 @@ do_positional:
>      /* Just a counter.  */
>      size_t cnt;
>  
> -    free (workstart);
> +    if (__builtin_expect (workstart != NULL, 0))
> +      free (workstart);

Given that in the past, for example, in commits
62605cbfcb3d2f118c9f64ce049220b82928e6d4 and
72e6cdfa2cd95240439c72705ab28a2eebb7d04e (ChangeLog in commit
0726cdf7dbdccdf0f99d910d5e7799d902a1ec38) such checks have been removed,
does this (and likewise for other cases) warrant a comment being added,
or some other form of (user-accessible) documentation update what this
change achieves?


GrÃÃe,
 Thomas

Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]