summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChase Douglas <chase.douglas@canonical.com>2012-04-20 14:16:07 -0700
committerChase Douglas <chase.douglas@canonical.com>2012-04-20 15:17:01 -0700
commit9daef33e32ba36c1f872691daeebbf98a73b4b25 (patch)
treefc8d5cfb387536d2bee77da4d01d80b5e1bc7c89
parent0e3061495f5da8a323db02e612c4f09688b7ade0 (diff)
Free XauFileName() static buffer at exit
XauFileName() may allocate and return a static buffer. The only way to ensure it is freed is to deallocate it when the program exits. Signed-off-by: Chase Douglas <chase.douglas@canonical.com> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--AuFileName.c17
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);