diff options
author | 2015-03-23 22:15:11 +0000 | |
---|---|---|
committer | 2015-03-23 22:15:11 +0000 | |
commit | 98e59ffb187d8e9b542eb7f7e9480784703b0090 (patch) | |
tree | a181c55baedebf63fdb80f7e63ba4e769facb6b3 /lib/libc/stdio/tempnam.c | |
parent | Add an helper routine if defined(DDB), which might help figuring out why (diff) | |
download | wireguard-openbsd-98e59ffb187d8e9b542eb7f7e9480784703b0090.tar.xz wireguard-openbsd-98e59ffb187d8e9b542eb7f7e9480784703b0090.zip |
fix memory leaks in tempnam(3) error paths
ok miod@ millert@ krw@ guenther@
Diffstat (limited to 'lib/libc/stdio/tempnam.c')
-rw-r--r-- | lib/libc/stdio/tempnam.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c index e3f2ab6476c..56d667dadd4 100644 --- a/lib/libc/stdio/tempnam.c +++ b/lib/libc/stdio/tempnam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tempnam.c,v 1.17 2013/09/30 12:02:35 millert Exp $ */ +/* $OpenBSD: tempnam.c,v 1.18 2015/03/23 22:15:11 jsg Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -58,7 +58,7 @@ tempnam(const char *dir, const char *pfx) f[strlen(f) - 1] == '/' ? "" : "/", pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); @@ -70,7 +70,7 @@ tempnam(const char *dir, const char *pfx) f[strlen(f) - 1] == '/' ? "" : "/", pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); @@ -80,7 +80,7 @@ tempnam(const char *dir, const char *pfx) len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); @@ -89,11 +89,12 @@ tempnam(const char *dir, const char *pfx) len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); +fail: sverrno = errno; free(name); errno = sverrno; |