summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2016-05-07 14:03:02 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2016-05-07 14:03:02 +0000
commitcc767cdc1e4a6251704710b15637f7bcab35189d (patch)
tree3ff37436248bb08f14f605d132b8cb6a3753cea5
parentdeb9d696f2eef0e3df4a0f7d3d476002595e6165 (diff)
Free memory if realloc fails. The application is most likely to terminate after
a failure, but if it does not we better clean up after ourselfs. OK deraadt@ and stefan@
-rw-r--r--usr.bin/vi/common/mem.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/usr.bin/vi/common/mem.h b/usr.bin/vi/common/mem.h
index 8dbff9d8d21..f7eeedb977a 100644
--- a/usr.bin/vi/common/mem.h
+++ b/usr.bin/vi/common/mem.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mem.h,v 1.8 2016/02/03 01:47:25 mmcc Exp $ */
+/* $OpenBSD: mem.h,v 1.9 2016/05/07 14:03:01 martijn Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -143,13 +143,21 @@
}
#define REALLOC(sp, p, size) { \
- if (((p) = (realloc((p), (size)))) == NULL) \
+ void *tmpp; \
+ if (((tmpp) = (realloc((p), (size)))) == NULL) { \
msgq((sp), M_SYSERR, NULL); \
+ free(p); \
+ } \
+ p = tmpp; \
}
#define REALLOCARRAY(sp, p, nelem, size) { \
- if (((p) = (reallocarray((p), (nelem), (size)))) == NULL) \
+ void *tmpp; \
+ if (((tmpp) = (reallocarray((p), (nelem), (size)))) == NULL) { \
msgq((sp), M_SYSERR, NULL); \
+ free(p); \
+ } \
+ p = tmpp; \
}
/*