> From: Chase Douglas <[email protected]> > Date: Fri, 20 Apr 2012 14:18:59 -0700 > > XauFileName() may allocate and return a static buffer. The only > way to ensure it is freed is to deallocate it when the program exits.
Which is fairly pointless given that the program is exiting anyway. I guess you're using some sort of tool to detect memory leaks. I don't think the additional code bloat is worth it to avoid what's arguably a false positive. > Signed-off-by: Chase Douglas <[email protected]> > --- > AuFileName.c | 17 ++++++++++++++++- > 1 files changed, 16 insertions(+), 1 deletions(-) > > diff --git a/AuFileName.c b/AuFileName.c > index f384f75..bc7b177 100644 > --- a/AuFileName.c > +++ b/AuFileName.c > @@ -31,13 +31,22 @@ in this Software without prior written authorization from > The Open Group. > #include <X11/Xos.h> > #include <stdlib.h> > > +static char *buf = NULL; > + > +static void > +free_filename_buffer(void) > +{ > + free(buf); > + buf = NULL; > +} > + > char * > XauFileName (void) > { > const char *slashDotXauthority = "/.Xauthority"; > char *name; > - static char *buf; > static int bsize; > + static int atexit_registered = 0; > #ifdef WIN32 > char dir[128]; > #endif > @@ -64,6 +73,12 @@ XauFileName (void) > buf = malloc ((unsigned) size); > if (!buf) > return NULL; > + > + if (!atexit_registered) { > + atexit(free_filename_buffer); > + atexit_registered = 1; > + } > + > bsize = size; > } > strcpy (buf, name); > -- > 1.7.9.1 > > _______________________________________________ > [email protected]: X.Org development > Archives: http://lists.x.org/archives/xorg-devel > Info: http://lists.x.org/mailman/listinfo/xorg-devel > _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
