Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make: prevent memory leaks from buffers
details: https://anonhg.NetBSD.org/src/rev/5f1856a00a2c
branches: trunk
changeset: 1027671:5f1856a00a2c
user: rillig <rillig%NetBSD.org@localhost>
date: Wed Dec 15 09:29:55 2021 +0000
description:
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:
usr.bin/make/buf.c | 7 ++++---
usr.bin/make/buf.h | 8 ++++----
usr.bin/make/make.h | 8 +++++++-
3 files changed, 15 insertions(+), 8 deletions(-)
diffs (79 lines):
diff -r 0551aa88ebb1 -r 5f1856a00a2c usr.bin/make/buf.c
--- a/usr.bin/make/buf.c Wed Dec 15 09:19:34 2021 +0000
+++ b/usr.bin/make/buf.c Wed Dec 15 09:29:55 2021 +0000
@@ -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 @@
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
diff -r 0551aa88ebb1 -r 5f1856a00a2c usr.bin/make/buf.h
--- a/usr.bin/make/buf.h Wed Dec 15 09:19:34 2021 +0000
+++ b/usr.bin/make/buf.h Wed Dec 15 09:29:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.44 2021/11/28 22:48:06 rillig Exp $ */
+/* $NetBSD: buf.h,v 1.45 2021/12/15 09:29:55 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -101,7 +101,7 @@
end[1] = '\0';
}
-MAKE_INLINE bool
+MAKE_INLINE bool MAKE_ATTR_USE
Buf_EndsWith(const Buffer *buf, char ch)
{
return buf->len > 0 && buf->data[buf->len - 1] == ch;
@@ -116,7 +116,7 @@
void Buf_Init(Buffer *);
void Buf_InitSize(Buffer *, size_t);
void Buf_Done(Buffer *);
-char *Buf_DoneData(Buffer *);
-char *Buf_DoneDataCompact(Buffer *);
+char *Buf_DoneData(Buffer *) MAKE_ATTR_USE;
+char *Buf_DoneDataCompact(Buffer *) MAKE_ATTR_USE;
#endif /* MAKE_BUF_H */
diff -r 0551aa88ebb1 -r 5f1856a00a2c usr.bin/make/make.h
--- a/usr.bin/make/make.h Wed Dec 15 09:19:34 2021 +0000
+++ b/usr.bin/make/make.h Wed Dec 15 09:29:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.272 2021/12/13 22:26:21 rillig Exp $ */
+/* $NetBSD: make.h,v 1.273 2021/12/15 09:29:55 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,6 +130,12 @@
#define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */
#endif
+#if MAKE_GNUC_PREREQ(4, 0)
+#define MAKE_ATTR_USE __attribute__((__warn_unused_result__))
+#else
+#define MAKE_ATTR_USE /* delete */
+#endif
+
#define MAKE_INLINE static inline MAKE_ATTR_UNUSED
/* MAKE_STATIC marks a function that may or may not be inlined. */
Home |
Main Index |
Thread Index |
Old Index