make: fix some more memory leaks

This commit is contained in:
rillig 2024-05-25 08:03:19 +00:00
parent 3ba972454a
commit c05c85b7d7
5 changed files with 28 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.292 2024/05/25 00:00:25 rillig Exp $ */
/* $NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -132,7 +132,7 @@
#include "job.h"
/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
MAKE_RCSID("$NetBSD: dir.c,v 1.292 2024/05/25 00:00:25 rillig Exp $");
MAKE_RCSID("$NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $");
/*
* A search path is a list of CachedDir structures. A CachedDir has in it the
@ -876,6 +876,7 @@ SearchPath_ExpandMiddle(SearchPath *path, const char *pattern,
(void)SearchPath_Add(partPath, dirpath);
DirExpandPath(wildcardComponent + 1, partPath, expansions);
SearchPath_Free(partPath);
free(dirpath);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.471 2024/05/07 18:26:22 sjg Exp $ */
/* $NetBSD: job.c,v 1.472 2024/05/25 08:03:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -141,7 +141,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: job.c,v 1.471 2024/05/07 18:26:22 sjg Exp $");
MAKE_RCSID("$NetBSD: job.c,v 1.472 2024/05/25 08:03:19 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@ -2482,6 +2482,7 @@ Job_ParseShell(char *line)
}
}
} else {
free(UNCONST(shellPath));
shellPath = path;
shellName = newShell.name != NULL ? newShell.name
: str_basename(path);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.724 2024/05/25 00:00:25 rillig Exp $ */
/* $NetBSD: parse.c,v 1.725 2024/05/25 08:03:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -105,7 +105,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: parse.c,v 1.724 2024/05/25 00:00:25 rillig Exp $");
MAKE_RCSID("$NetBSD: parse.c,v 1.725 2024/05/25 08:03:19 rillig Exp $");
/* Detects a multiple-inclusion guard in a makefile. */
typedef enum {
@ -2303,9 +2303,15 @@ ParseEOF(void)
Cond_EndFile();
if (curFile->guardState == GS_DONE)
HashTable_Set(&guards, curFile->name.str, curFile->guard);
else if (curFile->guard != NULL) {
if (curFile->guardState == GS_DONE) {
HashEntry *he = HashTable_CreateEntry(&guards,
curFile->name.str, NULL);
if (he->value != NULL) {
free(((Guard *)he->value)->name);
free(he->value);
}
HashEntry_Set(he, curFile->guard);
} else if (curFile->guard != NULL) {
free(curFile->guard->name);
free(curFile->guard);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.378 2024/02/07 06:43:02 rillig Exp $ */
/* $NetBSD: suff.c,v 1.379 2024/05/25 08:03:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -115,7 +115,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
MAKE_RCSID("$NetBSD: suff.c,v 1.378 2024/02/07 06:43:02 rillig Exp $");
MAKE_RCSID("$NetBSD: suff.c,v 1.379 2024/05/25 08:03:19 rillig Exp $");
typedef List SuffixList;
typedef ListNode SuffixListNode;
@ -1223,6 +1223,7 @@ ExpandWildcards(GNodeListNode *cln, GNode *pgn)
DEBUG1(SUFF, "%s...", name);
gn = Targ_GetNode(name);
free(name);
/* Insert gn before the original child. */
Lst_InsertBefore(&pgn->children, cln, gn);

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.1111 2024/05/25 00:00:25 rillig Exp $ */
/* $NetBSD: var.c,v 1.1112 2024/05/25 08:03:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -132,7 +132,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: var.c,v 1.1111 2024/05/25 00:00:25 rillig Exp $");
MAKE_RCSID("$NetBSD: var.c,v 1.1112 2024/05/25 08:03:19 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@ -2396,11 +2396,11 @@ ApplyModifier_Loop(const char **pp, ModChain *ch)
"In the :@ modifier, the variable name \"%s\" "
"must not contain a dollar",
args.var);
return AMR_CLEANUP;
goto cleanup_tvar;
}
if (!ParseModifierPart(pp, '@', VARE_PARSE_BALANCED, ch, &strBuf))
return AMR_CLEANUP;
goto cleanup_tvar;
str = LazyBuf_DoneGet(&strBuf);
args.body = str.str;
@ -2419,6 +2419,10 @@ done:
FStr_Done(&tvar);
FStr_Done(&str);
return AMR_OK;
cleanup_tvar:
FStr_Done(&tvar);
return AMR_CLEANUP;
}
static void