intel / intel-ipsec-mb

Intel(R) Multi-Buffer Crypto for IPSec
BSD 3-Clause "New" or "Revised" License
292 stars 88 forks source link

Memory leak of allocations pointed to by variant_list[i].avg_times #55

Closed ColinIanKing closed 4 years ago

ColinIanKing commented 4 years ago

In function run_tests in ipsec_perf.c any allocated avg_times buffers probably should be free'd before free'ing variant_list. This is a moot point because _exit() is being called afterwards anyhow, but it's nice to clean up correctly to clean up static analysis warnings :-)

2230        for (variant = 0, variant_ptr = variant_list;
2231             variant < total_variants;
2232             variant++, variant_ptr++) {
    CID 99591 (#4 of 4): Resource leak (RESOURCE_LEAK) 

    41. alloc_fn: Storage is returned from allocation function malloc.
    42. var_assign: Assigning: variant_ptr->avg_times = storage returned from malloc(at_size).
    43. var_assign: Assigning: variant_list->avg_times = variant_ptr->avg_times.

2233                variant_ptr->avg_times = (uint64_t *) malloc(at_size);

    44. Condition !variant_ptr->avg_times, taking false branch.
    47. Condition !variant_ptr->avg_times, taking false branch.

2234                if (!variant_ptr->avg_times) {
2235                        fprintf(stderr, "Cannot allocate memory\n");
2236                        goto exit_failure;
2237                }

and the free'ing:

2296exit_failure:
2297        if (variant_list != NULL)
    CID 99591 (#2 of 4): Resource leak (RESOURCE_LEAK) [select issue]
2298                free(variant_list);
2299        free_mem(&buf, &keys);
2300        free_mb_mgr(p_mgr);
2301        exit(EXIT_FAILURE);
pablodelara commented 4 years ago

Thanks for reporting, @ColinIanKing. Will fix it shortly.