summaryrefslogtreecommitdiffstats
path: root/apps/engine.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2016-05-11 21:14:57 +0100
committerDr. Stephen Henson <steve@openssl.org>2016-05-12 12:02:38 +0100
commit7c0ef8431845ea741012a5a6ff7063dca801fadd (patch)
tree29a5fe81356f6baf98b7d6162367879cd1e38ecb /apps/engine.c
parent3dfcb6a0ecbc210899e4b674331d0294189281b9 (diff)
Don't leak memory if realloc fails.
RT#4403 Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Diffstat (limited to 'apps/engine.c')
-rw-r--r--apps/engine.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/apps/engine.c b/apps/engine.c
index b60bfbc294..3b395b1c7d 100644
--- a/apps/engine.c
+++ b/apps/engine.c
@@ -107,13 +107,17 @@ static int append_buf(char **buf, int *size, const char *s)
}
if (strlen(*buf) + strlen(s) >= (unsigned int)*size) {
+ char *tmp;
*size += 256;
- *buf = OPENSSL_realloc(*buf, *size);
+ tmp = OPENSSL_realloc(*buf, *size);
+ if (tmp == NULL) {
+ OPENSSL_free(*buf);
+ *buf = NULL;
+ return 0;
+ }
+ *buf = tmp;
}
- if (*buf == NULL)
- return 0;
-
if (**buf != '\0')
OPENSSL_strlcat(*buf, ", ", *size);
OPENSSL_strlcat(*buf, s, *size);