-
Notifications
You must be signed in to change notification settings - Fork 65
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
dbfopen: possible memory leak with realloc when allocation fails #165
Comments
ymdatta
added a commit
to ymdatta/shapelib
that referenced
this issue
Oct 29, 2024
Fixes OSGeo#165 Signed-off-by: Mohan Yelugoti <[email protected]>
ymdatta
added a commit
to ymdatta/shapelib
that referenced
this issue
Oct 29, 2024
Fixes OSGeo#165 Signed-off-by: Mohan Yelugoti <[email protected]>
ymdatta
added a commit
to ymdatta/shapelib
that referenced
this issue
Nov 1, 2024
Fixes OSGeo#165 Signed-off-by: Mohan Yelugoti <[email protected]>
ymdatta
added a commit
to ymdatta/shapelib
that referenced
this issue
Nov 1, 2024
Fixes OSGeo#165 Signed-off-by: Mohan Yelugoti <[email protected]>
ymdatta
added a commit
to ymdatta/shapelib
that referenced
this issue
Nov 1, 2024
Fixes OSGeo#165 Signed-off-by: Mohan Yelugoti <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the bug?
While working on GRASS GIS I found some possible memory leak issues with the shape library, which is external to GRASS GIS, and imported from GDAL.
This was found using
cppcheck
static analysis tool.An example scenario (dbfopen.c#L462):
When realloc returns
NULL
for example in cases where there is not enough memory, we overwritepabyBuf
pointer to NULL, thus losing access to the memory previously pointed by thepabyBuf
and not freeing it, which causes memory leak. (In a successful scenario, realloc automatically frees the memory pointed topabyBuf
if its returning a different pointer)There are multiple
realloc
scenarios in the dbfopen.c which fall under same error category, though are not detected bycppcheck
directly.The solution I believe should be using a temporary pointer to store the address to pointer after reallocation and only if it's not NULL, assign it back.
Steps to reproduce the issue
Install cppcheck.
I have used version 2.7
Run
dbfopen.c
Should be independent of architecture and reproducible on all platforms.
Versions and provenance
I have checked latest development version with the cppcheck tool and observed the issue.
The text was updated successfully, but these errors were encountered: