crypto/engine/eng_dyn.c:400: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_strdup()` at line 395, column 29 is not reachable after line 400, column 13.
Showing all 54 steps of the trace


crypto/engine/eng_dyn.c:333:1: start of procedure dynamic_ctrl()
331.   }
332.   
333. > static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
334.   {
335.       dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);

crypto/engine/eng_dyn.c:335:5: Skipping dynamic_get_data_ctx(): empty list of specs
333.   static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
334.   {
335.       dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
           ^
336.       int initialised;
337.   

crypto/engine/eng_dyn.c:338:10: Taking false branch
336.       int initialised;
337.   
338.       if (!ctx) {
                ^
339.           ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_NOT_LOADED);
340.           return 0;

crypto/engine/eng_dyn.c:342:21: Condition is true
340.           return 0;
341.       }
342.       initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
                           ^
343.       /* All our control commands require the ENGINE to be uninitialised */
344.       if (initialised) {

crypto/engine/eng_dyn.c:342:20: 
340.           return 0;
341.       }
342. >     initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
343.       /* All our control commands require the ENGINE to be uninitialised */
344.       if (initialised) {

crypto/engine/eng_dyn.c:342:5: 
340.           return 0;
341.       }
342. >     initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
343.       /* All our control commands require the ENGINE to be uninitialised */
344.       if (initialised) {

crypto/engine/eng_dyn.c:344:9: Taking false branch
342.       initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
343.       /* All our control commands require the ENGINE to be uninitialised */
344.       if (initialised) {
               ^
345.           ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_ALREADY_LOADED);
346.           return 0;

crypto/engine/eng_dyn.c:348:5: 
346.           return 0;
347.       }
348. >     switch (cmd) {
349.       case DYNAMIC_CMD_SO_PATH:
350.           /* a NULL 'p' or a string of zero-length is the same thing */

crypto/engine/eng_dyn.c:349:5: Switch condition is false. Skipping switch case
347.       }
348.       switch (cmd) {
349.       case DYNAMIC_CMD_SO_PATH:
           ^
350.           /* a NULL 'p' or a string of zero-length is the same thing */
351.           if (p && (strlen((const char *)p) < 1))

crypto/engine/eng_dyn.c:359:5: Switch condition is false. Skipping switch case
357.               ctx->DYNAMIC_LIBNAME = NULL;
358.           return (ctx->DYNAMIC_LIBNAME ? 1 : 0);
359.       case DYNAMIC_CMD_NO_VCHECK:
           ^
360.           ctx->no_vcheck = ((i == 0) ? 0 : 1);
361.           return 1;

crypto/engine/eng_dyn.c:362:5: Switch condition is false. Skipping switch case
360.           ctx->no_vcheck = ((i == 0) ? 0 : 1);
361.           return 1;
362.       case DYNAMIC_CMD_ID:
           ^
363.           /* a NULL 'p' or a string of zero-length is the same thing */
364.           if (p && (strlen((const char *)p) < 1))

crypto/engine/eng_dyn.c:372:5: Switch condition is false. Skipping switch case
370.               ctx->engine_id = NULL;
371.           return (ctx->engine_id ? 1 : 0);
372.       case DYNAMIC_CMD_LIST_ADD:
           ^
373.           if ((i < 0) || (i > 2)) {
374.               ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);

crypto/engine/eng_dyn.c:379:5: Switch condition is false. Skipping switch case
377.           ctx->list_add_value = (int)i;
378.           return 1;
379.       case DYNAMIC_CMD_LOAD:
           ^
380.           return dynamic_load(e, ctx);
381.       case DYNAMIC_CMD_DIR_LOAD:

crypto/engine/eng_dyn.c:381:5: Switch condition is false. Skipping switch case
379.       case DYNAMIC_CMD_LOAD:
380.           return dynamic_load(e, ctx);
381.       case DYNAMIC_CMD_DIR_LOAD:
           ^
382.           if ((i < 0) || (i > 2)) {
383.               ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);

crypto/engine/eng_dyn.c:388:5: Switch condition is true. Entering switch case
386.           ctx->dir_load = (int)i;
387.           return 1;
388.       case DYNAMIC_CMD_DIR_ADD:
           ^
389.           /* a NULL 'p' or a string of zero-length is the same thing */
390.           if (!p || (strlen((const char *)p) < 1)) {

crypto/engine/eng_dyn.c:390:14: Taking false branch
388.       case DYNAMIC_CMD_DIR_ADD:
389.           /* a NULL 'p' or a string of zero-length is the same thing */
390.           if (!p || (strlen((const char *)p) < 1)) {
                    ^
391.               ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);
392.               return 0;

crypto/engine/eng_dyn.c:390:20: Taking false branch
388.       case DYNAMIC_CMD_DIR_ADD:
389.           /* a NULL 'p' or a string of zero-length is the same thing */
390.           if (!p || (strlen((const char *)p) < 1)) {
                          ^
391.               ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);
392.               return 0;

crypto/engine/eng_dyn.c:395:13: 
393.           }
394.           {
395. >             char *tmp_str = OPENSSL_strdup(p);
396.               if (!tmp_str) {
397.                   ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ERR_R_MALLOC_FAILURE);

crypto/o_str.c:121:1: start of procedure CRYPTO_strdup()
  119.   }
  120.   
  121. > char *CRYPTO_strdup(const char *str, const char* file, int line)
  122.   {
  123.       char *ret;

crypto/o_str.c:125:9: Taking false branch
  123.       char *ret;
  124.   
  125.       if (str == NULL)
                 ^
  126.           return NULL;
  127.       ret = CRYPTO_malloc(strlen(str) + 1, file, line);

crypto/o_str.c:127:5: 
  125.       if (str == NULL)
  126.           return NULL;
  127. >     ret = CRYPTO_malloc(strlen(str) + 1, file, line);
  128.       if (ret != NULL)
  129.           strcpy(ret, str);

crypto/mem.c:120:1: start of procedure CRYPTO_malloc()
    118.   }
    119.   
    120. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    121.   {
    122.       void *ret = NULL;

crypto/mem.c:122:5: 
    120.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    121.   {
    122. >     void *ret = NULL;
    123.   
    124.       if (num <= 0)

crypto/mem.c:124:9: Taking false branch
    122.       void *ret = NULL;
    123.   
    124.       if (num <= 0)
                   ^
    125.           return NULL;
    126.   

crypto/mem.c:127:5: 
    125.           return NULL;
    126.   
    127. >     allow_customize = 0;
    128.   #ifdef CRYPTO_MDEBUG
    129.       if (call_malloc_debug) {

crypto/mem.c:137:5: 
    135.       }
    136.   #else
    137. >     (void)file;
    138.       (void)line;
    139.       ret = malloc(num);

crypto/mem.c:138:5: 
    136.   #else
    137.       (void)file;
    138. >     (void)line;
    139.       ret = malloc(num);
    140.   #endif

crypto/mem.c:139:5: 
    137.       (void)file;
    138.       (void)line;
    139. >     ret = malloc(num);
    140.   #endif
    141.   

crypto/mem.c:154:5: 
    152.   #endif
    153.   
    154. >     return ret;
    155.   }
    156.   

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
    153.   
    154.       return ret;
    155. > }
    156.   
    157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/o_str.c:128:9: Taking true branch
  126.           return NULL;
  127.       ret = CRYPTO_malloc(strlen(str) + 1, file, line);
  128.       if (ret != NULL)
                 ^
  129.           strcpy(ret, str);
  130.       return ret;

crypto/o_str.c:129:9: 
  127.       ret = CRYPTO_malloc(strlen(str) + 1, file, line);
  128.       if (ret != NULL)
  129. >         strcpy(ret, str);
  130.       return ret;
  131.   }

crypto/o_str.c:130:5: 
  128.       if (ret != NULL)
  129.           strcpy(ret, str);
  130. >     return ret;
  131.   }
  132.   

crypto/o_str.c:131:1: return from a call to CRYPTO_strdup
  129.           strcpy(ret, str);
  130.       return ret;
  131. > }
  132.   
  133.   char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line)

crypto/engine/eng_dyn.c:396:18: Taking false branch
394.           {
395.               char *tmp_str = OPENSSL_strdup(p);
396.               if (!tmp_str) {
                        ^
397.                   ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ERR_R_MALLOC_FAILURE);
398.                   return 0;

crypto/engine/eng_dyn.c:400:13: 
398.                   return 0;
399.               }
400. >             sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1);
401.           }
402.           return 1;

include/openssl/safestack.h:214:1: start of procedure sk_OPENSSL_STRING_insert()
  212.    * dealt with in the autogenerated macros below.
  213.    */
  214. > DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
  215.   
  216.   /*

crypto/stack/stack.c:167:1: start of procedure sk_insert()
    165.   }
    166.   
    167. > int sk_insert(_STACK *st, void *data, int loc)
    168.   {
    169.       char **s;

crypto/stack/stack.c:171:9: Taking false branch
    169.       char **s;
    170.   
    171.       if (st == NULL)
                   ^
    172.           return 0;
    173.       if (st->num_alloc <= st->num + 1) {

crypto/stack/stack.c:173:9: Taking true branch
    171.       if (st == NULL)
    172.           return 0;
    173.       if (st->num_alloc <= st->num + 1) {
                   ^
    174.           s = OPENSSL_realloc((char *)st->data,
    175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);

crypto/stack/stack.c:174:9: 
    172.           return 0;
    173.       if (st->num_alloc <= st->num + 1) {
    174. >         s = OPENSSL_realloc((char *)st->data,
    175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
    176.           if (s == NULL)

crypto/mem.c:166:1: start of procedure CRYPTO_realloc()
      164.   }
      165.   
      166. > void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
      167.   {
      168.       if (str == NULL)

crypto/mem.c:168:9: Taking true branch
      166.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
      167.   {
      168.       if (str == NULL)
                     ^
      169.           return CRYPTO_malloc(num, file, line);
      170.   

crypto/mem.c:169:9: 
      167.   {
      168.       if (str == NULL)
      169. >         return CRYPTO_malloc(num, file, line);
      170.   
      171.       if (num == 0) {

crypto/mem.c:120:1: start of procedure CRYPTO_malloc()
        118.   }
        119.   
        120. > void *CRYPTO_malloc(size_t num, const char *file, int line)
        121.   {
        122.       void *ret = NULL;

crypto/mem.c:122:5: 
        120.   void *CRYPTO_malloc(size_t num, const char *file, int line)
        121.   {
        122. >     void *ret = NULL;
        123.   
        124.       if (num <= 0)

crypto/mem.c:124:9: Taking true branch
        122.       void *ret = NULL;
        123.   
        124.       if (num <= 0)
                       ^
        125.           return NULL;
        126.   

crypto/mem.c:125:9: 
        123.   
        124.       if (num <= 0)
        125. >         return NULL;
        126.   
        127.       allow_customize = 0;

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
        153.   
        154.       return ret;
        155. > }
        156.   
        157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:191:1: return from a call to CRYPTO_realloc
      189.       return realloc(str, num);
      190.   
      191. > }
      192.   
      193.   void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,

crypto/stack/stack.c:176:13: Taking true branch
    174.           s = OPENSSL_realloc((char *)st->data,
    175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
    176.           if (s == NULL)
                       ^
    177.               return (0);
    178.           st->data = s;

crypto/stack/stack.c:177:13: 
    175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
    176.           if (s == NULL)
    177. >             return (0);
    178.           st->data = s;
    179.           st->num_alloc *= 2;

crypto/stack/stack.c:191:1: return from a call to sk_insert
    189.       st->sorted = 0;
    190.       return (st->num);
    191. > }
    192.   
    193.   void *sk_delete_ptr(_STACK *st, void *p)

include/openssl/safestack.h:214:1: return from a call to sk_OPENSSL_STRING_insert
  212.    * dealt with in the autogenerated macros below.
  213.    */
  214. > DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
  215.   
  216.   /*

static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
{
    dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
    int initialised;
    if (!ctx) {
        ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_NOT_LOADED);
        return 0;
    }
    initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
    if (initialised) {
        ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_ALREADY_LOADED);
        return 0;
    }
    switch (cmd) {
    case DYNAMIC_CMD_SO_PATH:
        if (p && (strlen((const char *)p) < 1))
            p = NULL;
        OPENSSL_free(ctx->DYNAMIC_LIBNAME);
        if (p)
            ctx->DYNAMIC_LIBNAME = OPENSSL_strdup(p);
        else
            ctx->DYNAMIC_LIBNAME = NULL;
        return (ctx->DYNAMIC_LIBNAME ? 1 : 0);
    case DYNAMIC_CMD_NO_VCHECK:
        ctx->no_vcheck = ((i == 0) ? 0 : 1);
        return 1;
    case DYNAMIC_CMD_ID:
        if (p && (strlen((const char *)p) < 1))
            p = NULL;
        OPENSSL_free(ctx->engine_id);
        if (p)
            ctx->engine_id = OPENSSL_strdup(p);
        else
            ctx->engine_id = NULL;
        return (ctx->engine_id ? 1 : 0);
    case DYNAMIC_CMD_LIST_ADD:
        if ((i < 0) || (i > 2)) {
            ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);
            return 0;
        }
        ctx->list_add_value = (int)i;
        return 1;
    case DYNAMIC_CMD_LOAD:
        return dynamic_load(e, ctx);
    case DYNAMIC_CMD_DIR_LOAD:
        if ((i < 0) || (i > 2)) {
            ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);
            return 0;
        }
        ctx->dir_load = (int)i;
        return 1;
    case DYNAMIC_CMD_DIR_ADD:
        if (!p || (strlen((const char *)p) < 1)) {
            ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);
            return 0;
        }
        {
            char *tmp_str = OPENSSL_strdup(p);
            if (!tmp_str) {
                ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ERR_R_MALLOC_FAILURE);
                return 0;
            }
            sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1);
        }
        return 1;
    default:
        break;
    }
    ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
    return 0;
}
['static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))\n{\n    dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);\n    int initialised;\n    if (!ctx) {\n        ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_NOT_LOADED);\n        return 0;\n    }\n    initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);\n    if (initialised) {\n        ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_ALREADY_LOADED);\n        return 0;\n    }\n    switch (cmd) {\n    case DYNAMIC_CMD_SO_PATH:\n        if (p && (strlen((const char *)p) < 1))\n            p = NULL;\n        OPENSSL_free(ctx->DYNAMIC_LIBNAME);\n        if (p)\n            ctx->DYNAMIC_LIBNAME = OPENSSL_strdup(p);\n        else\n            ctx->DYNAMIC_LIBNAME = NULL;\n        return (ctx->DYNAMIC_LIBNAME ? 1 : 0);\n    case DYNAMIC_CMD_NO_VCHECK:\n        ctx->no_vcheck = ((i == 0) ? 0 : 1);\n        return 1;\n    case DYNAMIC_CMD_ID:\n        if (p && (strlen((const char *)p) < 1))\n            p = NULL;\n        OPENSSL_free(ctx->engine_id);\n        if (p)\n            ctx->engine_id = OPENSSL_strdup(p);\n        else\n            ctx->engine_id = NULL;\n        return (ctx->engine_id ? 1 : 0);\n    case DYNAMIC_CMD_LIST_ADD:\n        if ((i < 0) || (i > 2)) {\n            ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);\n            return 0;\n        }\n        ctx->list_add_value = (int)i;\n        return 1;\n    case DYNAMIC_CMD_LOAD:\n        return dynamic_load(e, ctx);\n    case DYNAMIC_CMD_DIR_LOAD:\n        if ((i < 0) || (i > 2)) {\n            ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);\n            return 0;\n        }\n        ctx->dir_load = (int)i;\n        return 1;\n    case DYNAMIC_CMD_DIR_ADD:\n        if (!p || (strlen((const char *)p) < 1)) {\n            ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_INVALID_ARGUMENT);\n            return 0;\n        }\n        {\n            char *tmp_str = OPENSSL_strdup(p);\n            if (!tmp_str) {\n                ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ERR_R_MALLOC_FAILURE);\n                return 0;\n            }\n            sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1);\n        }\n        return 1;\n    default:\n        break;\n    }\n    ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);\n    return 0;\n}', 'char *CRYPTO_strdup(const char *str, const char* file, int line)\n{\n    char *ret;\n    if (str == NULL)\n        return NULL;\n    ret = CRYPTO_malloc(strlen(str) + 1, file, line);\n    if (ret != NULL)\n        strcpy(ret, str);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n    char **s;\n    if (st == NULL)\n        return 0;\n    if (st->num_alloc <= st->num + 1) {\n        s = OPENSSL_realloc((char *)st->data,\n                            (unsigned int)sizeof(char *) * st->num_alloc * 2);\n        if (s == NULL)\n            return (0);\n        st->data = s;\n        st->num_alloc *= 2;\n    }\n    if ((loc >= (int)st->num) || (loc < 0))\n        st->data[st->num] = data;\n    else {\n        memmove(&(st->data[loc + 1]),\n                &(st->data[loc]), sizeof(char *) * (st->num - loc));\n        st->data[loc] = data;\n    }\n    st->num++;\n    st->sorted = 0;\n    return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    (void)file;\n    (void)line;\n#endif\n    return realloc(str, num);\n}']