Make sure aep_close_connection() is declared and has a prototype that's
[openssl.git] / crypto / stack / stack.c
index d2c640075b33f844482d87518f3435db5e98f234..2496f28a8c01b0faaf36d8355495ce249aa2855c 100644 (file)
@@ -106,18 +106,25 @@ STACK *sk_dup(STACK *sk)
        ret->comp=sk->comp;
        return(ret);
 err:
+       if(ret)
+               sk_free(ret);
        return(NULL);
        }
 
+STACK *sk_new_null(void)
+       {
+       return sk_new((int (*)(const char * const *, const char * const *))0);
+       }
+
 STACK *sk_new(int (*c)(const char * const *, const char * const *))
        {
        STACK *ret;
        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;
@@ -125,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);
        }
 
@@ -310,18 +317,18 @@ char *sk_set(STACK *st, int i, char *value)
 }
 
 void sk_sort(STACK *st)
-    {
-    if (!st->sorted)
        {
-       int (*comp_func)(const void *,const void *);
-
-       /* same comment as in sk_find ... previously st->comp was declared
-        * as a (void*,void*) callback type, but this made the population
-        * of the callback pointer illogical - our callbacks compare
-        * type** with type**, so we leave the casting until absolutely
-        * necessary (ie. "now"). */
-       comp_func=(int (*)(const void *,const void *))(st->comp);
-       qsort(st->data,st->num,sizeof(char *), comp_func);
-       st->sorted=1;
+       if (st && !st->sorted)
+               {
+               int (*comp_func)(const void *,const void *);
+
+               /* same comment as in sk_find ... previously st->comp was declared
+                * as a (void*,void*) callback type, but this made the population
+                * of the callback pointer illogical - our callbacks compare
+                * type** with type**, so we leave the casting until absolutely
+                * necessary (ie. "now"). */
+               comp_func=(int (*)(const void *,const void *))(st->comp);
+               qsort(st->data,st->num,sizeof(char *), comp_func);
+               st->sorted=1;
+               }
        }
-    }