Fix coverity issue: CID 1466486 - Resource leak in OSSL_STORE
[openssl.git] / test / ossl_store_test.c
1 /*
2  * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <openssl/store.h>
11 #include <openssl/ui.h>
12 #include "testutil.h"
13
14 typedef enum OPTION_choice {
15     OPT_ERR = -1,
16     OPT_EOF = 0,
17     OPT_INFILE,
18     OPT_TEST_ENUM
19 } OPTION_CHOICE;
20
21 static const char *infile = NULL;
22
23 static int test_store_open(void)
24 {
25     int ret = 0;
26     OSSL_STORE_CTX *sctx = NULL;
27     UI_METHOD *ui_method = NULL;
28
29     ret = TEST_ptr(ui_method= UI_create_method("DummyUI"))
30           && TEST_ptr(sctx = OSSL_STORE_open_with_libctx(infile, NULL, NULL,
31                                                          ui_method, NULL,
32                                                          NULL, NULL));
33     UI_destroy_method(ui_method);
34     OSSL_STORE_close(sctx);
35     return ret;
36 }
37
38 const OPTIONS *test_get_options(void)
39 {
40     static const OPTIONS test_options[] = {
41         OPT_TEST_OPTIONS_DEFAULT_USAGE,
42         { "in", OPT_INFILE, '<', },
43         { NULL }
44     };
45     return test_options;
46 }
47
48 int setup_tests(void)
49 {
50     OPTION_CHOICE o;
51
52     while ((o = opt_next()) != OPT_EOF) {
53         switch (o) {
54         case OPT_INFILE:
55             infile = opt_arg();
56             break;
57         case OPT_TEST_CASES:
58            break;
59         default:
60         case OPT_ERR:
61             return 0;
62         }
63     }
64
65     ADD_TEST(test_store_open);
66     return 1;
67 }