Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/services_mkdb Avoid memory leak on empty lines (htt...
details: https://anonhg.NetBSD.org/src/rev/9dde456c5c07
branches: trunk
changeset: 981829:9dde456c5c07
user: christos <christos%NetBSD.org@localhost>
date: Mon Mar 22 03:28:55 2021 +0000
description:
Avoid memory leak on empty lines (https://reviews.freebsd.org/D29370)
diffstat:
usr.sbin/services_mkdb/uniq.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diffs (45 lines):
diff -r 2214c73e7107 -r 9dde456c5c07 usr.sbin/services_mkdb/uniq.c
--- a/usr.sbin/services_mkdb/uniq.c Mon Mar 22 01:36:10 2021 +0000
+++ b/usr.sbin/services_mkdb/uniq.c Mon Mar 22 03:28:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uniq.c,v 1.6 2014/06/21 17:48:07 christos Exp $ */
+/* $NetBSD: uniq.c,v 1.7 2021/03/22 03:28:55 christos Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: uniq.c,v 1.6 2014/06/21 17:48:07 christos Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.7 2021/03/22 03:28:55 christos Exp $");
#include <stdio.h>
#include <string.h>
@@ -126,11 +126,12 @@
for (p = (const unsigned char *)origline; l && *p && isspace(*p);
p++, l--)
continue;
+ if (*p == '\0' || l == 0)
+ return 0;
+
cline = emalloc(l + 1);
(void)memcpy(cline, p, l);
cline[l] = '\0';
- if (*cline == '\0')
- return 0;
complen = 0;
hasalnum = 0;
@@ -160,6 +161,11 @@
--complen;
}
*q = '\0';
+ if (!hasalnum) {
+ free(cline);
+ cline = NULL;
+ complen = 0;
+ }
*compline = cline;
*len = complen;
return hasalnum;
Home |
Main Index |
Thread Index |
Old Index