-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
lib/ogsf: Fix Resource Leak issue in gp3.c #4977
base: main
Are you sure you want to change the base?
Conversation
lib/ogsf/gp3.c
Outdated
db_close_database_shutdown_driver(driver); | ||
Vect_destroy_field_info(Fi); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db_close_database_shutdown_driver(driver); | |
Vect_destroy_field_info(Fi); | |
if (driver) { | |
db_close_database_shutdown_driver(driver); | |
Vect_destroy_field_info(Fi); | |
} |
The db driver might not be available, see L202.
Also, the calls to db_select_value()
above need to be protected with if statements if there is no database connection (lines 235ff).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the calls to db_select_value() above need to be protected with if statements if there is no database connection (lines 235ff).
- If
Fi
fails to be set (L201ff), thendriver
is not set either: both remain NULL. - If
Fi
is successfully set, butdriver
fails to open leads to G_fatal_error.
So, both Fi
and driver
are either NULL or !NULL from L211.
With driver
and Fi
uninitiated (NULL), db_select_value
returns -1
and continues the loop:
nvals = db_select_value(driver, Fi->table, Fi->key, cat,
gp->tstyle->color_column, &value);
if (nvals < 1)
continue;
Checking for driver
is not necessary as it works as is. There's no doubt this function may be improved for clarity, but that change – as far as I understand – is not needed for the initial aim of this PR.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There are also related CID:1207706 and 1207707 for this file, which would be good to address here. (You can filter issues by file location under "Edit settings" (cogwheel icon), add e.g. /lib/ogsf/gp3.c` for "File".) |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This pull request fixes issue identified by Coverity Scan (CID : 1207703, 1207704, 1415564).
Used G_free(), db_close_database_shutdown_driver(), Vect_destroy_field_info() to fix the issue.