Module Name: src Committed By: wiz Date: Sun Jan 17 23:13:32 UTC 2010
Modified Files: src/lib/libc/ssp: gets_chk.c Log Message: Free malloc()ed buffer in error case. Found by cppcheck. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/ssp/gets_chk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/ssp/gets_chk.c diff -u src/lib/libc/ssp/gets_chk.c:1.5 src/lib/libc/ssp/gets_chk.c:1.6 --- src/lib/libc/ssp/gets_chk.c:1.5 Mon Apr 28 20:23:00 2008 +++ src/lib/libc/ssp/gets_chk.c Sun Jan 17 23:13:32 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: gets_chk.c,v 1.5 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: gets_chk.c,v 1.6 2010/01/17 23:13:32 wiz Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: gets_chk.c,v 1.5 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: gets_chk.c,v 1.6 2010/01/17 23:13:32 wiz Exp $"); /*LINTLIBRARY*/ @@ -54,8 +54,10 @@ if ((abuf = malloc(slen + 1)) == NULL) return gets(buf); - if (fgets(abuf, (int)(slen + 1), stdin) == NULL) + if (fgets(abuf, (int)(slen + 1), stdin) == NULL) { + free(abuf); return NULL; + } len = strlen(abuf); if (len > 0 && abuf[len - 1] == '\n')