Fix a memory leak in 'sk_dup' in the case a realloc() fails. Also, tidy up

a bit of weird code in sk_new.
This commit is contained in:
Geoff Thorpe 2001-05-31 19:01:08 +00:00
parent a95541d61e
commit d918f85146
2 changed files with 11 additions and 5 deletions

View File

@ -11,6 +11,10 @@
*) applies to 0.9.6a (/0.9.6b) and 0.9.7 *) applies to 0.9.6a (/0.9.6b) and 0.9.7
+) applies to 0.9.7 only +) applies to 0.9.7 only
+) Fix a memory leak in 'sk_dup()' in the case reallocation fails. (Also
tidy up some unecessarily weird code in 'sk_new()').
[Geoff, reported by Diego Tartara <dtartara@novamens.com>]
+) Change the key loading routines for ENGINEs to use the same kind +) Change the key loading routines for ENGINEs to use the same kind
callback (pem_password_cb) as all other routines that need this callback (pem_password_cb) as all other routines that need this
kind of callback. kind of callback.

View File

@ -106,6 +106,8 @@ STACK *sk_dup(STACK *sk)
ret->comp=sk->comp; ret->comp=sk->comp;
return(ret); return(ret);
err: err:
if(ret)
sk_free(ret);
return(NULL); return(NULL);
} }
@ -120,9 +122,9 @@ STACK *sk_new(int (*c)(const char * const *, const char * const *))
int i; int i;
if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL) if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)
goto err0; goto err;
if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL) if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
goto err1; goto err;
for (i=0; i<MIN_NODES; i++) for (i=0; i<MIN_NODES; i++)
ret->data[i]=NULL; ret->data[i]=NULL;
ret->comp=c; ret->comp=c;
@ -130,9 +132,9 @@ STACK *sk_new(int (*c)(const char * const *, const char * const *))
ret->num=0; ret->num=0;
ret->sorted=0; ret->sorted=0;
return(ret); return(ret);
err1: err:
OPENSSL_free(ret); if(ret)
err0: OPENSSL_free(ret);
return(NULL); return(NULL);
} }