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

memory leak in g2_unpack3() if undefined grid template number is used #162

Closed
edwardhartnett opened this issue Oct 27, 2021 · 2 comments · Fixed by #180
Closed

memory leak in g2_unpack3() if undefined grid template number is used #162

edwardhartnett opened this issue Oct 27, 2021 · 2 comments · Fixed by #180
Assignees
Labels
bug Something isn't working

Comments

@edwardhartnett
Copy link
Contributor

There's a test for this (commented out) in tst_unpack.c.

@edwardhartnett edwardhartnett added the bug Something isn't working label Oct 27, 2021
@edwardhartnett edwardhartnett self-assigned this Oct 27, 2021
@edwardhartnett
Copy link
Contributor Author

In the function we have this code:

        /*   Get Grid Definition Template */
        if (!(mapgrid = getgridtemplate(ligds[4])))
        {         /* undefined template */
            ierr = 5;
            return ierr;
        }

But we have already done:

ligds = calloc(5, sizeof(g2int));

So when we exit, we have a memory leak.

@edwardhartnett
Copy link
Contributor Author

edwardhartnett commented Nov 3, 2021

Thing is, ligds is an array of 5 g2int. Really, there's no reason to malloc it, it can just be declared. BUT, in other code, this pointer is later freed. So I will just cause it to be freed in this error condition, so there is no leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant