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

lib/ogsf: Fix Resource Leak issue in gp3.c #4977

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

Conversation

ShubhamDesai
Copy link
Contributor

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.

@github-actions github-actions bot added C Related code is in C libraries labels Jan 22, 2025
lib/ogsf/gp3.c Outdated
Comment on lines 300 to 301
db_close_database_shutdown_driver(driver);
Vect_destroy_field_info(Fi);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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).

Copy link
Contributor

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), then driver is not set either: both remain NULL.
  • If Fi is successfully set, but driver 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.

lib/ogsf/gp3.c Show resolved Hide resolved
Shubham Vasudeo Desai and others added 3 commits January 28, 2025 16:04
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>
@nilason
Copy link
Contributor

nilason commented Jan 31, 2025

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".)

@nilason nilason added this to the 8.5.0 milestone Jan 31, 2025
Shubham Vasudeo Desai and others added 4 commits February 2, 2025 15:44
lib/ogsf/gp3.c Outdated Show resolved Hide resolved
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 libraries
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants