diff options
author | Geoff Thorpe <geoff@openssl.org> | 2001-05-31 19:01:08 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2001-05-31 19:01:08 +0000 |
commit | d918f85146ca8e01d721518aac7575976aebdfd1 (patch) | |
tree | d6e683b085c687fc30b8ae94c5310d40fa607d99 /crypto/stack | |
parent | a95541d61e37878216abaa8e00ff3c75cff9a7c2 (diff) |
Fix a memory leak in 'sk_dup' in the case a realloc() fails. Also, tidy up
a bit of weird code in sk_new.
Diffstat (limited to 'crypto/stack')
-rw-r--r-- | crypto/stack/stack.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c index 9a75e433d7..2496f28a8c 100644 --- a/crypto/stack/stack.c +++ b/crypto/stack/stack.c @@ -106,6 +106,8 @@ STACK *sk_dup(STACK *sk) ret->comp=sk->comp; return(ret); err: + if(ret) + sk_free(ret); return(NULL); } @@ -120,9 +122,9 @@ STACK *sk_new(int (*c)(const char * const *, const char * const *)) int i; if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL) - goto err0; + goto err; if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL) - goto err1; + goto err; for (i=0; i<MIN_NODES; i++) ret->data[i]=NULL; ret->comp=c; @@ -130,9 +132,9 @@ STACK *sk_new(int (*c)(const char * const *, const char * const *)) ret->num=0; ret->sorted=0; return(ret); -err1: - OPENSSL_free(ret); -err0: +err: + if(ret) + OPENSSL_free(ret); return(NULL); } |