diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2016-05-11 21:14:57 +0100 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2016-05-12 12:02:38 +0100 |
commit | 7c0ef8431845ea741012a5a6ff7063dca801fadd (patch) | |
tree | 29a5fe81356f6baf98b7d6162367879cd1e38ecb /ssl/t1_ext.c | |
parent | 3dfcb6a0ecbc210899e4b674331d0294189281b9 (diff) |
Don't leak memory if realloc fails.
RT#4403
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Diffstat (limited to 'ssl/t1_ext.c')
-rw-r--r-- | ssl/t1_ext.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ssl/t1_ext.c b/ssl/t1_ext.c index 3bbe1fd826..281613185e 100644 --- a/ssl/t1_ext.c +++ b/ssl/t1_ext.c @@ -205,7 +205,7 @@ static int custom_ext_meth_add(custom_ext_methods *exts, void *add_arg, custom_ext_parse_cb parse_cb, void *parse_arg) { - custom_ext_method *meth; + custom_ext_method *meth, *tmp; /* * Check application error: if add_cb is not set free_cb will never be * called. @@ -225,15 +225,17 @@ static int custom_ext_meth_add(custom_ext_methods *exts, /* Search for duplicate */ if (custom_ext_find(exts, ext_type)) return 0; - exts->meths = OPENSSL_realloc(exts->meths, - (exts->meths_count + - 1) * sizeof(custom_ext_method)); + tmp = OPENSSL_realloc(exts->meths, + (exts->meths_count + 1) * sizeof(custom_ext_method)); - if (!exts->meths) { + if (tmp == NULL) { + OPENSSL_free(exts->meths); + exts->meths = NULL; exts->meths_count = 0; return 0; } + exts->meths = tmp; meth = exts->meths + exts->meths_count; memset(meth, 0, sizeof(*meth)); meth->parse_cb = parse_cb; |