This patch fixes a leak of the ext_san structure when
sk_X509_EXTENSION_push() failed. sk_X509_EXTENSION_pop_free() is already
suppose to free it, so ext_san must be set to NULL upon success to avoid
a double-free.
Must be backported to 3.2 and later.
X509_REQ *x = NULL;
X509_NAME *nm = NULL;
STACK_OF(X509_EXTENSION) *exts = NULL;
- X509_EXTENSION *ext_san;
+ X509_EXTENSION *ext_san = NULL;
char *str_san = NULL;
int i = 0;
if (!sk_X509_EXTENSION_push(exts, ext_san))
goto error;
+
+ ext_san = NULL; /* handle double-free upon error */
+
if (!X509_REQ_add_extensions(x, exts))
goto error;
return x;
error:
+ X509_EXTENSION_free(ext_san);
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
X509_REQ_free(x);
X509_NAME_free(nm);