Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memor leak in function testqzEndStreamInvalidParam #109

Open
ColinIanKing opened this issue Feb 8, 2024 · 2 comments
Open

memor leak in function testqzEndStreamInvalidParam #109

ColinIanKing opened this issue Feb 8, 2024 · 2 comments

Comments

@ColinIanKing
Copy link

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

void *testqzEndStreamInvalidParam(void *arg, int test_no)
2671	{
2672	    int rc = -1;
2673	    QzSession_T comp_sess = {0}, decomp_sess = {0};
2674	    QzStream_T comp_strm = {0};
2675	    QzSessionParams_T comp_params = {0};
2676	    uint8_t *orig_src, *comp_src, *decomp_src;
2677	    size_t orig_sz, comp_sz, decomp_sz;
2678	    unsigned int slice_sz = 0, done = 0;
2679	    unsigned int consumed = 0, produced = 0;
2680	    unsigned int input_left = 0, last = 0;
2681	 
2682	    QzSession_T *test_sess = NULL;
2683	    QzStream_T *test_strm = NULL;
2684	 
2685	    TestArg_T *test_arg = (TestArg_T *) arg;
2686	 
2687	    orig_sz = comp_sz = decomp_sz = test_arg->src_sz;
2688	    orig_src = malloc(orig_sz);
2689	    comp_src = malloc(comp_sz);
	
	Memory is allocated	

2690	    decomp_src = calloc(orig_sz, 1);
2691	 
2692	    if (qzGetDefaults(&comp_params) != QZ_OK) {
	
	Assuming the condition is true	
	Taking true branch	

2693	        QZ_ERROR("Err: fail to get default params.\n");
	
	Potential leak of memory pointed to by 'comp_src'

2694	        return NULL;
2695	    }
@GarenJian-Intel
Copy link
Contributor

Thanks!
We will fix this issue.
Jira ticket created: https://jira.devtools.intel.com/browse/QATAPP-31728

@nefigtut
Copy link

+1 to this. our code security scanner blames the same lines:

Defect type: CPPCHECK_WARNING:
QATzip-1.2.0/test/main.c:2694: error[memleak]: Memory leak: orig_src
QATzip-1.2.0/test/main.c:2694: error[memleak]: Memory leak: decomp_src
QATzip-1.2.0/test/main.c:2694: error[memleak]: Memory leak: comp_src
QATzip-1.2.0/test/main.c:2520: error[memleak]: Memory leak: orig_src
QATzip-1.2.0/test/main.c:2520: error[memleak]: Memory leak: decomp_src
QATzip-1.2.0/test/main.c:2520: error[memleak]: Memory leak: comp_src

so, orig_src, comp_src and decomp_src can leak at test/main.c:2694 and test/main.c:2520:

void *testqzEndStreamInvalidParam(void *arg, int test_no)
{
...
    // ALLOC HERE
    orig_src = malloc(orig_sz);
    comp_src = malloc(comp_sz);
    decomp_src = calloc(orig_sz, 1);
    
    if (qzGetDefaults(&comp_params) != QZ_OK) {
        QZ_ERROR("Err: fail to get default params.\n");
        return NULL; //<-- LEAK HERE
    }

and

void *testqzDecompressStreamInvalidParam(void *arg, int test_no)
{
...
    // ALLOC HERE
    orig_src = malloc(orig_sz);
    comp_src = malloc(comp_sz);
    decomp_src = calloc(orig_sz, 1);
    
    if (qzGetDefaults(&comp_params) != QZ_OK) {
        QZ_ERROR("Err: fail to get default params.\n");
        return NULL; //<-- LEAK HERE
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants