Skip to content

r.stats: Fix Resource Leak issue in raw_stats.c #5910

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

Merged
merged 4 commits into from
Jun 24, 2025

Conversation

ShubhamDesai
Copy link
Contributor

This pull request fixes issue identified by Coverity Scan (CID : 1207664, 1207665, 1207666).
Used G_free() to fix this issue.

@github-actions github-actions bot added raster Related to raster data processing C Related code is in C module labels Jun 18, 2025
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.

rast and rastp are both an array of array (void**), you need to deal with that.
(One of them is tricky, I'll leave you to solve that :)

@nilason nilason added this to the 8.5.0 milestone Jun 23, 2025
@ShubhamDesai
Copy link
Contributor Author

rast and rastp are both an array of array (void**), you need to deal with that. (One of them is tricky, I'll leave you to solve that :)

Done

For rast: Since each rast[i] holds a buffer for a raster row (allocated with Rast_allocate_buf), I added a loop to call G_free(rast[i]) for each one. After that, I G_free(rast) to release the array of pointers itself.

For rastp : While rastp is an array of pointers itself (so I G_free(rastp)), its individual pointers (rastp[i]) actually just point into the buffers that rast[i] owns. So, there's no need to free rastp[i] individually, as that memory is already handled when rast[i] is freed.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@nilason nilason merged commit 84a8a6c into OSGeo:main Jun 24, 2025
30 of 32 checks passed
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 module raster Related to raster data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants