test/ct_test.c:182: error: MEMORY_LEAK
  memory dynamically allocated by call to `BIO_new()` at line 157, column 19 is not reachable after line 182, column 5.
Showing all 54 steps of the trace


test/ct_test.c:150:1: start of procedure compare_sct_list_printout()
148.   }
149.   
150. > static int compare_sct_list_printout(STACK_OF(SCT) *sct,
151.       const char *expected_output)
152.   {

test/ct_test.c:153:5: 
151.       const char *expected_output)
152.   {
153. >     BIO *text_buffer = NULL;
154.       char *actual_output = NULL;
155.       int result = 1;

test/ct_test.c:154:5: 
152.   {
153.       BIO *text_buffer = NULL;
154. >     char *actual_output = NULL;
155.       int result = 1;
156.   

test/ct_test.c:155:5: 
153.       BIO *text_buffer = NULL;
154.       char *actual_output = NULL;
155. >     int result = 1;
156.   
157.       text_buffer = BIO_new(BIO_s_mem());

test/ct_test.c:157:5: 
155.       int result = 1;
156.   
157. >     text_buffer = BIO_new(BIO_s_mem());
158.       if (text_buffer == NULL) {
159.           fprintf(stderr, "Unable to allocate buffer\n");

crypto/bio/bss_mem.c:63:1: start of procedure BIO_s_mem()
  61.    */
  62.   
  63. > const BIO_METHOD *BIO_s_mem(void)
  64.   {
  65.       return (&mem_method);

crypto/bio/bss_mem.c:65:5: 
  63.   const BIO_METHOD *BIO_s_mem(void)
  64.   {
  65. >     return (&mem_method);
  66.   }
  67.   

crypto/bio/bss_mem.c:66:1: return from a call to BIO_s_mem
  64.   {
  65.       return (&mem_method);
  66. > }
  67.   
  68.   const BIO_METHOD *BIO_s_secmem(void)

crypto/bio/bio_lib.c:17:1: start of procedure BIO_new()
  15.   #include <openssl/stack.h>
  16.   
  17. > BIO *BIO_new(const BIO_METHOD *method)
  18.   {
  19.       BIO *ret = OPENSSL_malloc(sizeof(*ret));

crypto/bio/bio_lib.c:19:5: 
  17.   BIO *BIO_new(const BIO_METHOD *method)
  18.   {
  19. >     BIO *ret = OPENSSL_malloc(sizeof(*ret));
  20.   
  21.       if (ret == NULL) {

crypto/mem.c:71:1: start of procedure CRYPTO_malloc()
    69.   }
    70.   
    71. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    72.   {
    73.       void *ret = NULL;

crypto/mem.c:73:5: 
    71.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    72.   {
    73. >     void *ret = NULL;
    74.   
    75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:75:9: Taking false branch
    73.       void *ret = NULL;
    74.   
    75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                  ^
    76.           return malloc_impl(num, file, line);
    77.   

crypto/mem.c:78:9: Taking false branch
    76.           return malloc_impl(num, file, line);
    77.   
    78.       if (num <= 0)
                  ^
    79.           return NULL;
    80.   

crypto/mem.c:81:5: 
    79.           return NULL;
    80.   
    81. >     allow_customize = 0;
    82.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
    83.       if (call_malloc_debug) {

crypto/mem.c:91:5: 
    89.       }
    90.   #else
    91. >     osslargused(file); osslargused(line);
    92.       ret = malloc(num);
    93.   #endif

crypto/mem.c:91:24: 
    89.       }
    90.   #else
    91. >     osslargused(file); osslargused(line);
    92.       ret = malloc(num);
    93.   #endif

crypto/mem.c:92:5: 
    90.   #else
    91.       osslargused(file); osslargused(line);
    92. >     ret = malloc(num);
    93.   #endif
    94.   

crypto/mem.c:95:5: 
    93.   #endif
    94.   
    95. >     return ret;
    96.   }
    97.   

crypto/mem.c:96:1: return from a call to CRYPTO_malloc
    94.   
    95.       return ret;
    96. > }
    97.   
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/bio/bio_lib.c:21:9: Taking false branch
  19.       BIO *ret = OPENSSL_malloc(sizeof(*ret));
  20.   
  21.       if (ret == NULL) {
                ^
  22.           BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);
  23.           return (NULL);

crypto/bio/bio_lib.c:25:10: Taking false branch
  23.           return (NULL);
  24.       }
  25.       if (!BIO_set(ret, method)) {
                 ^
  26.           OPENSSL_free(ret);
  27.           ret = NULL;

crypto/bio/bio_lib.c:29:5: 
  27.           ret = NULL;
  28.       }
  29. >     return (ret);
  30.   }
  31.   

crypto/bio/bio_lib.c:30:1: return from a call to BIO_new
  28.       }
  29.       return (ret);
  30. > }
  31.   
  32.   int BIO_set(BIO *bio, const BIO_METHOD *method)

test/ct_test.c:158:9: Taking false branch
156.   
157.       text_buffer = BIO_new(BIO_s_mem());
158.       if (text_buffer == NULL) {
               ^
159.           fprintf(stderr, "Unable to allocate buffer\n");
160.           goto end;

test/ct_test.c:163:5: 
161.       }
162.   
163. >     SCT_LIST_print(sct, text_buffer, 0, "\n", NULL);
164.   
165.       /* Append null terminator because we're about to use the buffer contents

crypto/ct/ct_prn.c:114:1: start of procedure SCT_LIST_print()
  112.   }
  113.   
  114. > void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,
  115.                       const char *separator, const CTLOG_STORE *log_store)
  116.   {

crypto/ct/ct_prn.c:117:5: 
  115.                       const char *separator, const CTLOG_STORE *log_store)
  116.   {
  117. >     int sct_count = sk_SCT_num(sct_list);
  118.       int i;
  119.   

include/openssl/ct.h:57:1: start of procedure sk_SCT_num()
    55.   } sct_validation_status_t;
    56.   
    57. > DEFINE_STACK_OF(SCT)
    58.   DEFINE_STACK_OF(CTLOG)
    59.   

crypto/stack/stack.c:265:1: start of procedure OPENSSL_sk_num()
      263.   }
      264.   
      265. > int OPENSSL_sk_num(const OPENSSL_STACK *st)
      266.   {
      267.       if (st == NULL)

crypto/stack/stack.c:267:9: Taking true branch
      265.   int OPENSSL_sk_num(const OPENSSL_STACK *st)
      266.   {
      267.       if (st == NULL)
                     ^
      268.           return -1;
      269.       return st->num;

crypto/stack/stack.c:268:9: 
      266.   {
      267.       if (st == NULL)
      268. >         return -1;
      269.       return st->num;
      270.   }

crypto/stack/stack.c:270:1: return from a call to OPENSSL_sk_num
      268.           return -1;
      269.       return st->num;
      270. > }
      271.   
      272.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)

include/openssl/ct.h:57:1: return from a call to sk_SCT_num
    55.   } sct_validation_status_t;
    56.   
    57. > DEFINE_STACK_OF(SCT)
    58.   DEFINE_STACK_OF(CTLOG)
    59.   

crypto/ct/ct_prn.c:120:10: 
  118.       int i;
  119.   
  120. >     for (i = 0; i < sct_count; ++i) {
  121.           SCT *sct = sk_SCT_value(sct_list, i);
  122.   

crypto/ct/ct_prn.c:120:17: Loop condition is false. Leaving loop
  118.       int i;
  119.   
  120.       for (i = 0; i < sct_count; ++i) {
                         ^
  121.           SCT *sct = sk_SCT_value(sct_list, i);
  122.   

crypto/ct/ct_prn.c:127:1: return from a call to SCT_LIST_print
  125.               BIO_printf(out, "%s", separator);
  126.       }
  127. > }

test/ct_test.c:167:9: 
165.       /* Append null terminator because we're about to use the buffer contents
166.       * as a string. */
167. >     if (BIO_write(text_buffer, "\0", 1) != 1) {
168.           fprintf(stderr, "Failed to append null terminator to SCT text\n");
169.           goto end;

crypto/bio/bio_lib.c:223:1: start of procedure BIO_write()
  221.   }
  222.   
  223. > int BIO_write(BIO *b, const void *in, int inl)
  224.   {
  225.       int i;

crypto/bio/bio_lib.c:228:9: Taking false branch
  226.       long (*cb) (BIO *, int, const char *, int, long, long);
  227.   
  228.       if (b == NULL)
                 ^
  229.           return (0);
  230.   

crypto/bio/bio_lib.c:231:5: 
  229.           return (0);
  230.   
  231. >     cb = b->callback;
  232.       if ((b->method == NULL) || (b->method->bwrite == NULL)) {
  233.           BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);

crypto/bio/bio_lib.c:232:10: Taking false branch
  230.   
  231.       cb = b->callback;
  232.       if ((b->method == NULL) || (b->method->bwrite == NULL)) {
                  ^
  233.           BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);
  234.           return (-2);

crypto/bio/bio_lib.c:232:33: Taking false branch
  230.   
  231.       cb = b->callback;
  232.       if ((b->method == NULL) || (b->method->bwrite == NULL)) {
                                         ^
  233.           BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);
  234.           return (-2);

crypto/bio/bio_lib.c:237:10: Taking false branch
  235.       }
  236.   
  237.       if ((cb != NULL) &&
                  ^
  238.           ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0))
  239.           return (i);

crypto/bio/bio_lib.c:241:10: Taking false branch
  239.           return (i);
  240.   
  241.       if (!b->init) {
                  ^
  242.           BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED);
  243.           return (-2);

crypto/bio/bio_lib.c:246:5: Skipping __function_pointer__(): unresolved function pointer
  244.       }
  245.   
  246.       i = b->method->bwrite(b, in, inl);
             ^
  247.   
  248.       if (i > 0)

crypto/bio/bio_lib.c:248:9: Taking false branch
  246.       i = b->method->bwrite(b, in, inl);
  247.   
  248.       if (i > 0)
                 ^
  249.           b->num_write += (uint64_t)i;
  250.   

crypto/bio/bio_lib.c:251:9: Taking false branch
  249.           b->num_write += (uint64_t)i;
  250.   
  251.       if (cb != NULL)
                 ^
  252.           i = (int)cb(b, BIO_CB_WRITE | BIO_CB_RETURN, in, inl, 0L, (long)i);
  253.       return (i);

crypto/bio/bio_lib.c:253:5: 
  251.       if (cb != NULL)
  252.           i = (int)cb(b, BIO_CB_WRITE | BIO_CB_RETURN, in, inl, 0L, (long)i);
  253. >     return (i);
  254.   }
  255.   

crypto/bio/bio_lib.c:254:1: return from a call to BIO_write
  252.           i = (int)cb(b, BIO_CB_WRITE | BIO_CB_RETURN, in, inl, 0L, (long)i);
  253.       return (i);
  254. > }
  255.   
  256.   int BIO_puts(BIO *b, const char *in)

test/ct_test.c:167:9: Taking true branch
165.       /* Append null terminator because we're about to use the buffer contents
166.       * as a string. */
167.       if (BIO_write(text_buffer, "\0", 1) != 1) {
               ^
168.           fprintf(stderr, "Failed to append null terminator to SCT text\n");
169.           goto end;

test/ct_test.c:168:9: 
166.       * as a string. */
167.       if (BIO_write(text_buffer, "\0", 1) != 1) {
168. >         fprintf(stderr, "Failed to append null terminator to SCT text\n");
169.           goto end;
170.       }

test/ct_test.c:181:1: 
179.       }
180.   
181. > end:
182.       BIO_free(text_buffer);
183.       return result;

test/ct_test.c:182:5: Skipping BIO_free(): empty list of specs
180.   
181.   end:
182.       BIO_free(text_buffer);
           ^
183.       return result;
184.   }

static int compare_sct_list_printout(STACK_OF(SCT) *sct,
    const char *expected_output)
{
    BIO *text_buffer = NULL;
    char *actual_output = NULL;
    int result = 1;
    text_buffer = BIO_new(BIO_s_mem());
    if (text_buffer == NULL) {
        fprintf(stderr, "Unable to allocate buffer\n");
        goto end;
    }
    SCT_LIST_print(sct, text_buffer, 0, "\n", NULL);
    if (BIO_write(text_buffer, "\0", 1) != 1) {
        fprintf(stderr, "Failed to append null terminator to SCT text\n");
        goto end;
    }
    BIO_get_mem_data(text_buffer, &actual_output);
    result = strcmp(actual_output, expected_output);
    if (result != 0) {
        fprintf(stderr,
            "Expected SCT printout:\n%s\nActual SCT printout:\n%s\n",
            expected_output, actual_output);
    }
end:
    BIO_free(text_buffer);
    return result;
}
['static int compare_sct_list_printout(STACK_OF(SCT) *sct,\n    const char *expected_output)\n{\n    BIO *text_buffer = NULL;\n    char *actual_output = NULL;\n    int result = 1;\n    text_buffer = BIO_new(BIO_s_mem());\n    if (text_buffer == NULL) {\n        fprintf(stderr, "Unable to allocate buffer\\n");\n        goto end;\n    }\n    SCT_LIST_print(sct, text_buffer, 0, "\\n", NULL);\n    if (BIO_write(text_buffer, "\\0", 1) != 1) {\n        fprintf(stderr, "Failed to append null terminator to SCT text\\n");\n        goto end;\n    }\n    BIO_get_mem_data(text_buffer, &actual_output);\n    result = strcmp(actual_output, expected_output);\n    if (result != 0) {\n        fprintf(stderr,\n            "Expected SCT printout:\\n%s\\nActual SCT printout:\\n%s\\n",\n            expected_output, actual_output);\n    }\nend:\n    BIO_free(text_buffer);\n    return result;\n}', 'const BIO_METHOD *BIO_s_mem(void)\n{\n    return (&mem_method);\n}', 'BIO *BIO_new(const BIO_METHOD *method)\n{\n    BIO *ret = OPENSSL_malloc(sizeof(*ret));\n    if (ret == NULL) {\n        BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    if (!BIO_set(ret, method)) {\n        OPENSSL_free(ret);\n        ret = NULL;\n    }\n    return (ret);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\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    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,\n                    const char *separator, const CTLOG_STORE *log_store)\n{\n    int sct_count = sk_SCT_num(sct_list);\n    int i;\n    for (i = 0; i < sct_count; ++i) {\n        SCT *sct = sk_SCT_value(sct_list, i);\n        SCT_print(sct, out, indent, log_store);\n        if (i < sk_SCT_num(sct_list) - 1)\n            BIO_printf(out, "%s", separator);\n    }\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\n}', 'int BIO_write(BIO *b, const void *in, int inl)\n{\n    int i;\n    long (*cb) (BIO *, int, const char *, int, long, long);\n    if (b == NULL)\n        return (0);\n    cb = b->callback;\n    if ((b->method == NULL) || (b->method->bwrite == NULL)) {\n        BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);\n        return (-2);\n    }\n    if ((cb != NULL) &&\n        ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0))\n        return (i);\n    if (!b->init) {\n        BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED);\n        return (-2);\n    }\n    i = b->method->bwrite(b, in, inl);\n    if (i > 0)\n        b->num_write += (uint64_t)i;\n    if (cb != NULL)\n        i = (int)cb(b, BIO_CB_WRITE | BIO_CB_RETURN, in, inl, 0L, (long)i);\n    return (i);\n}']