This patch removes a potential memory leak in make_tempfile (in
arch/um/os-Linux/mem.c).
If tempdir is NULL or as long as MAXPATHLEN, the function will return
without freeing the previously
malloced tempname, resulting in a memory leak. Another way to fix this
issue is to replace :
if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
return -1;
with:
if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
goto out;
But I think the way in the attached patch is cleaner, as it doesn't
malloc tempname at all if it's not necessary.
Cheers,
Thomas
---
arch/um/os-Linux/mem.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index e696144..e135422 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -170,14 +170,14 @@ static int __init make_tempfile(const char
*template, char **out_tempname,
int fd;
which_tmpdir();
- tempname = malloc(MAXPATHLEN);
- if (tempname == NULL)
- return -1;
-
find_tempdir();
if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
return -1;
+ tempname = malloc(MAXPATHLEN);
+ if (tempname == NULL)
+ return -1;
+
if (template[0] != '/')
strcpy(tempname, tempdir);
else
--
1.7.2.3
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel