summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2006-04-09 19:03:32 +0000
committerchristos <christos@NetBSD.org>2006-04-09 19:03:32 +0000
commit5800a5519e1fe99bc031e58334a0a84476246168 (patch)
tree401ea45f298d35cbf97e74b8e0202b001069310c /usr.bin/patch
parente90cb419e0abcd9c8bd2172780c3fe309935b0bd (diff)
Coverity CID 2078, 2079, 2080: Plug memory leaks.
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/pch.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index 6becda81659..2810ba65f16 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pch.c,v 1.19 2003/07/30 08:51:04 itojun Exp $ */
+/* $NetBSD: pch.c,v 1.20 2006/04/09 19:03:32 christos Exp $ */
/*
* Copyright (c) 1988, Larry Wall
@@ -24,7 +24,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pch.c,v 1.19 2003/07/30 08:51:04 itojun Exp $");
+__RCSID("$NetBSD: pch.c,v 1.20 2006/04/09 19:03:32 christos Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -259,24 +259,34 @@ intuit_diff_type(void)
fcl_line = p_input_line;
p_indent = indent; /* assume this for now */
}
- if (!stars_last_line && strnEQ(s, "*** ", 4))
+ if (!stars_last_line && strnEQ(s, "*** ", 4)) {
+ if (oldtmp)
+ free(oldtmp);
oldtmp = xstrdup(s + 4);
- else if (strnEQ(s, "--- ", 4))
+ } else if (strnEQ(s, "--- ", 4)) {
+ if (newtmp)
+ free(newtmp);
newtmp = xstrdup(s + 4);
- else if (strnEQ(s, "+++ ", 4))
+ } else if (strnEQ(s, "+++ ", 4)) {
+ if (oldtmp)
+ free(oldtmp);
oldtmp = xstrdup(s + 4); /* pretend it is the old name */
- else if (strnEQ(s, "Index:", 6))
+ } else if (strnEQ(s, "Index:", 6)) {
+ if (indtmp)
+ free(indtmp);
indtmp = xstrdup(s + 6);
- else if (strnEQ(s, "Prereq:", 7)) {
+ } else if (strnEQ(s, "Prereq:", 7)) {
for (t = s + 7; isspace((unsigned char)*t); t++)
;
+ if (revision)
+ free(revision);
revision = xstrdup(t);
for (t = revision;
*t && !isspace((unsigned char)*t);
t++)
;
*t = '\0';
- if (!*revision) {
+ if (*revision == '\0') {
free(revision);
revision = NULL;
}