apps: make sure prog_init only calculates once
authorRichard Levitte <levitte@openssl.org>
Sun, 31 Dec 2017 07:44:12 +0000 (08:44 +0100)
committerRichard Levitte <levitte@openssl.org>
Sat, 6 Jan 2018 18:27:57 +0000 (19:27 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5002)

apps/openssl.c

index 2cb49cb..dd7463e 100644 (file)
@@ -787,12 +787,19 @@ static void list_disabled(void)
 
 static LHASH_OF(FUNCTION) *prog_init(void)
 {
-    LHASH_OF(FUNCTION) *ret;
+    static LHASH_OF(FUNCTION) *ret = NULL;
+    static int prog_inited = 0;
     FUNCTION *f;
     size_t i;
 
+    if (prog_inited)
+        return ret;
+
+    prog_inited = 1;
+
     /* Sort alphabetically within category. For nicer help displays. */
-    for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
+    for (i = 0, f = functions; f->name != NULL; ++f, ++i)
+        ;
     qsort(functions, i, sizeof(*functions), SortFnByName);
 
     if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)