From 5800a5519e1fe99bc031e58334a0a84476246168 Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 9 Apr 2006 19:03:32 +0000 Subject: [PATCH] Coverity CID 2078, 2079, 2080: Plug memory leaks. --- usr.bin/patch/pch.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 6becda81659f..2810ba65f16e 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 #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; }