intel / QATzip

Compression Library accelerated by Intel® QuickAssist Technology
https://developer.intel.com/quickassist
Other
140 stars 52 forks source link

memory leak in function testqzDecompressStreamInvalidParam #108

Closed ColinIanKing closed 3 months ago

ColinIanKing commented 9 months ago

the return path in line 2520 is not free'ing the allocated objects orig_src, comp_src, decomp_src, leaking to (non-fatal) memory leaks.

void *testqzDecompressStreamInvalidParam(void *arg, int test_no)
2498    {
2499        int rc = -1;
2500        QzSession_T comp_sess = {0}, decomp_sess = {0};
2501        QzStream_T comp_strm = {0};
2502        QzSessionParams_T comp_params = {0};
2503        uint8_t *orig_src, *comp_src, *decomp_src;
2504        size_t orig_sz, comp_sz, decomp_sz;
2505        unsigned int slice_sz = 0, done = 0;
2506        unsigned int consumed = 0, produced = 0;
2507        unsigned int input_left = 0, last = 0;
2508        QzSession_T *test_sess = NULL;
2509        QzStream_T *test_strm = NULL;
2510     
2511        TestArg_T *test_arg = (TestArg_T *) arg;
2512     
2513        orig_sz = comp_sz = decomp_sz = test_arg->src_sz;
2514        orig_src = malloc(orig_sz);

    Memory is allocated 

2515        comp_src = malloc(comp_sz);
2516        decomp_src = calloc(orig_sz, 1);
2517     
2518        if (qzGetDefaults(&comp_params) != QZ_OK) {

    Assuming the condition is true  
    Taking true branch  

2519            QZ_ERROR("Err: fail to get default params.\n");

    Potential leak of memory pointed to by 'orig_src'

2520            return NULL;
2521        }
GarenJian-Intel commented 8 months ago

Thanks! We will fix it. Created jira ticket: https://jira.devtools.intel.com/browse/QATAPP-31728