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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

crypto/engine/eng_dyn.c:401:13: 
399.                   return 0;
400.               }
401. >             sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1);
402.           }
403.           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:166:1: start of procedure sk_insert()
    164.   }
    165.   
    166. > int sk_insert(_STACK *st, void *data, int loc)
    167.   {
    168.       char **s;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

crypto/stack/stack.c:190:1: return from a call to sk_insert
    188.       st->sorted = 0;
    189.       return (st->num);
    190. > }
    191.   
    192.   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#ifndef OPENSSL_NO_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#ifndef OPENSSL_NO_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}']