From: Christos Zoulas Date: Mon, 23 Nov 2009 16:14:11 +0000 (-0500) Subject: From: Krisztian Kovacs X-Git-Tag: am-utils-6_2_rc1~18 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=ccf769f7dbaccb2ce9f8a2f270b2bcc89bf790ff;p=am-utils-6.2.git From: Krisztian Kovacs Date: Tue, 29 Jan 2008 17:59:19 +0100 Subject: [PATCH 01/20] Fix filename buffer leak in mtab_linux.c The temporary filename buffer was leaked in lock_mtab(). --- diff --git a/ChangeLog b/ChangeLog index 16c561e9..27ade558 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-11-23 Christos Zoulas + + * The temporary filename buffer was leaked in lock_mtab(). + From: Krisztian Kovacs + 2009-10-27 Christos Zoulas * Deal with errno.h->sys/errno.h better diff --git a/conf/mtab/mtab_linux.c b/conf/mtab/mtab_linux.c index e641c7e9..7736014c 100644 --- a/conf/mtab/mtab_linux.c +++ b/conf/mtab/mtab_linux.c @@ -160,6 +160,7 @@ lock_mtab(void) int tries = 100000, i; char *linktargetfile; size_t l; + int rc = 1; /* * Redhat's original code set a signal handler called "handler()" for all @@ -206,7 +207,8 @@ lock_mtab(void) (void) unlink(linktargetfile); plog(XLOG_ERROR, "can't link lock file %s: %s ", MOUNTED_LOCK, strerror(errsv)); - return 0; + rc = 0; + goto error; } lockfile_fd = open(MOUNTED_LOCK, O_WRONLY); @@ -221,7 +223,8 @@ lock_mtab(void) (void) unlink(linktargetfile); plog(XLOG_ERROR,"can't open lock file %s: %s ", MOUNTED_LOCK, strerror(errsv)); - return 0; + rc = 0; + goto error; } flock.l_type = F_WRLCK; @@ -251,7 +254,8 @@ lock_mtab(void) plog(XLOG_ERROR, "can't lock lock file %s: %s", MOUNTED_LOCK, (errno == EINTR) ? "timed out" : strerror(errsv)); - return 0; + rc = 0; + goto error; } alarm(0); /* @@ -267,11 +271,19 @@ lock_mtab(void) plog(XLOG_ERROR, "Cannot create link %s; Perhaps there is a stale lock file?", MOUNTED_LOCK); + rc = 0; + goto error; } close(lockfile_fd); } } - return 1; + +error: + if (linktargetfile != NULL) { + XFREE(linktargetfile); + } + + return rc; }