From e379dafa6d63e14f1c79fd4ad7a2a491428ecdfd Mon Sep 17 00:00:00 2001 From: rillig Date: Wed, 15 Dec 2021 09:29:55 +0000 Subject: 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. --- usr.bin/make/buf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'usr.bin/make/buf.c') 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 -- cgit