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

i.pca: Fix Resource Leak issue #4664

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ShubhamDesai
Copy link
Contributor

@ShubhamDesai ShubhamDesai commented Nov 6, 2024

This pull request fixes issue identified by coverity scan (CID : 1207830, 1207835, 1207833, 1207834, 1207836, 1207837)
G_free() is used.

@github-actions github-actions bot added C Related code is in C module imagery labels Nov 6, 2024
Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not misreading the code, sum2 and rowbuf are both 2D arrays, of which each part also needs to be freed.

This will lead to too much repetitive code for freeing resources, so I'd suggest we use goto with a return value variable.

@nilason nilason added this to the 8.5.0 milestone Nov 7, 2024
Shubham Vasudeo Desai added 2 commits November 8, 2024 17:30
@ShubhamDesai
Copy link
Contributor Author

If I'm not misreading the code, sum2 and rowbuf are both 2D arrays, of which each part also needs to be freed.

This will lead to too much repetitive code for freeing resources, so I'd suggest we use goto with a return value variable.

Done

}
for (i = 0; i < bands; i++)
mu[i] = sum[i] / count;

cleanup:
for (i = 0; i < bands; i++) {
if (sum2[i])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check for NULL before free.

Also, I'd prefer a more descriptive goto label name (free_exit, comes to my mind, but you may have another suggestion).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.
Also removed if condition for G_free(sd) and G_free(sumsq)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C imagery module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants