From 6380eb140ca001846a4b30a0d3ccd6a16f8e0a7d Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 13 May 2006 22:28:04 +0000 Subject: [PATCH] Coverity CID 3269: Fix memory leak. --- fortune/fortune/fortune.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fortune/fortune/fortune.c b/fortune/fortune/fortune.c index c9fb8a3b..3a56e9ad 100644 --- a/fortune/fortune/fortune.c +++ b/fortune/fortune/fortune.c @@ -1,4 +1,4 @@ -/* $NetBSD: fortune.c,v 1.48 2006/03/21 20:25:55 christos Exp $ */ +/* $NetBSD: fortune.c,v 1.49 2006/05/13 22:28:04 christos Exp $ */ /*- * Copyright (c) 1986, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1986, 1993\n\ #if 0 static char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: fortune.c,v 1.48 2006/03/21 20:25:55 christos Exp $"); +__RCSID("$NetBSD: fortune.c,v 1.49 2006/05/13 22:28:04 christos Exp $"); #endif #endif /* not lint */ @@ -552,14 +552,13 @@ over: * individual files -- if we're scanning a directory, * we'll pick up the -o file anyway. */ - if (All_forts && offensive != NULL) { + if (All_forts && offensive != NULL && path != offensive) { path = offensive; if (tpath) { free(tpath); tpath = NULL; } - offensive = NULL; - DPRINTF(1, (stderr, "\ttrying \"%s\"\n", path)); + DPRINTF(1, (stderr, "\ttrying \"%s\"\n", tfile)); tf = off_name(tfile); free(tfile); tfile = tf; @@ -569,6 +568,8 @@ over: int n = add_file(percent, tfile, FORTDIR, head, tail, parent); free(tfile); + if (offensive) + free(offensive); return n; } if (parent == NULL) @@ -578,6 +579,8 @@ over: tpath = NULL; } free(tfile); + if (offensive) + free(offensive); return FALSE; } -- 2.47.1