summaryrefslogtreecommitdiff
path: root/usr.bin/make/buf.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-12-15 09:29:55 +0000
committerrillig <rillig@NetBSD.org>2021-12-15 09:29:55 +0000
commite379dafa6d63e14f1c79fd4ad7a2a491428ecdfd (patch)
treeda93384b872ad24c3d8057beca9d16845d43ae7e /usr.bin/make/buf.c
parent09a4507e449d0fa578a94cd79117298b72268ee3 (diff)
make: prevent memory leaks from buffers
The warning about unused function results would have prevented the memory leak that was fixed in cond.c 1.303 from 2021-12-13.
Diffstat (limited to 'usr.bin/make/buf.c')
-rw-r--r--usr.bin/make/buf.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c
index 8c26cfa2495..b07f25d73b4 100644
--- a/usr.bin/make/buf.c
+++ b/usr.bin/make/buf.c
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.53 2021/11/28 22:48:06 rillig Exp $ */
+/* $NetBSD: buf.c,v 1.54 2021/12/15 09:29:55 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,7 +75,7 @@
#include "make.h"
/* "@(#)buf.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: buf.c,v 1.53 2021/11/28 22:48:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.54 2021/12/15 09:29:55 rillig Exp $");
/* Make space in the buffer for adding at least 16 more bytes. */
void
@@ -214,8 +214,9 @@ Buf_DoneDataCompact(Buffer *buf)
if (buf->cap - buf->len >= BUF_COMPACT_LIMIT) {
/* We trust realloc to be smart */
char *data = bmake_realloc(buf->data, buf->len + 1);
+ buf->data = NULL;
data[buf->len] = '\0'; /* XXX: unnecessary */
- Buf_DoneData(buf);
+ Buf_Done(buf);
return data;
}
#endif