free up the memory if it fails
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 23 Jun 1990 13:40:04 +0000 (05:40 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 23 Jun 1990 13:40:04 +0000 (05:40 -0800)
SCCS-vsn: lib/libc/stdio/tempnam.c 4.8

usr/src/lib/libc/stdio/tempnam.c

index 1a2884d..76f6444 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tempnam.c  4.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)tempnam.c  4.8 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
@@ -63,5 +63,7 @@ tempnam(dir, pfx)
        if (f = mktemp(name))
                return(f);
        (void)sprintf(name, "/tmp/%sXXXXXX", pfx ? "" : pfx);
        if (f = mktemp(name))
                return(f);
        (void)sprintf(name, "/tmp/%sXXXXXX", pfx ? "" : pfx);
-       return(mktemp(name));
+       if (!(f = mktemp(name)))
+               (void)free(name);
+       return(f);
 }
 }