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

fix potential leak found by coverity #198

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

chipitsine
Copy link
Contributor

@chipitsine chipitsine commented Oct 27, 2024

*** CID 446774:  Resource leaks  (RESOURCE_LEAK)
/DriverManager/SQLDriverConnect.c: 469 in __get_pair() 463
464         __get_attr( cp, &keyword, &value );
465         if ( keyword )
466         {
467             con_p = malloc( sizeof( *con_p ));
468             if ( !con_p )
>>>     CID 446774:  Resource leaks  (RESOURCE_LEAK)
>>>     Variable "value" going out of scope leaks the storage it points to.
469                 return NULL;
470             con_p -> keyword = keyword;
471             con_p -> attribute = value;
472             return con_p;
473         }
474         else

*** CID 446773:  Resource leaks  (RESOURCE_LEAK)
/DriverManager/SQLDriverConnect.c: 469 in __get_pair() 463
464         __get_attr( cp, &keyword, &value );
465         if ( keyword )
466         {
467             con_p = malloc( sizeof( *con_p ));
468             if ( !con_p )
>>>     CID 446773:  Resource leaks  (RESOURCE_LEAK)
>>>     Variable "keyword" going out of scope leaks the storage it points to.
469                 return NULL;
470             con_p -> keyword = keyword;
471             con_p -> attribute = value;
472             return con_p;
473         }
474         else

*** CID 446774:  Resource leaks  (RESOURCE_LEAK)
/DriverManager/SQLDriverConnect.c: 469 in __get_pair()
463
464         __get_attr( cp, &keyword, &value );
465         if ( keyword )
466         {
467             con_p = malloc( sizeof( *con_p ));
468             if ( !con_p )
>>>     CID 446774:  Resource leaks  (RESOURCE_LEAK)
>>>     Variable "value" going out of scope leaks the storage it points to.
469                 return NULL;
470             con_p -> keyword = keyword;
471             con_p -> attribute = value;
472             return con_p;
473         }
474         else

*** CID 446773:  Resource leaks  (RESOURCE_LEAK)
/DriverManager/SQLDriverConnect.c: 469 in __get_pair()
463
464         __get_attr( cp, &keyword, &value );
465         if ( keyword )
466         {
467             con_p = malloc( sizeof( *con_p ));
468             if ( !con_p )
>>>     CID 446773:  Resource leaks  (RESOURCE_LEAK)
>>>     Variable "keyword" going out of scope leaks the storage it points to.
469                 return NULL;
470             con_p -> keyword = keyword;
471             con_p -> attribute = value;
472             return con_p;
473         }
474         else
@chipitsine chipitsine marked this pull request as ready for review October 27, 2024 18:04
@chipitsine
Copy link
Contributor Author

from my view there's bigger problem when local variables are returned out of a function.
I wonder why coverity does not worry about it, I plan to have look at it later

@lurcher
Copy link
Owner

lurcher commented Oct 27, 2024 via email

@chipitsine
Copy link
Contributor Author

the following is suspicious

image

but that code is there for ~15 years. If there were a problem, it must appear somehow. What makes me think my assumption (about returning local variables|) is wrong

@chipitsine
Copy link
Contributor Author

@lurcher , can we merge it since it addresses leaks ?

@lurcher
Copy link
Owner

lurcher commented Nov 11, 2024

I don't understand where the leak is. the local variables you mention, are pointers, they are set to point to allocated memory in the call to __get_attr, then the pointed to, allocated memory is returned in the returned allocated structure. Just where does the problem occur?

@chipitsine
Copy link
Contributor Author

if NULL is returned, so con_p is leaked

@lurcher
Copy link
Owner

lurcher commented Nov 11, 2024

Ahh, ok, I can see that. Will fix that.

@lurcher lurcher merged commit 93b0d9d into lurcher:master Nov 11, 2024
2 checks passed
@chipitsine chipitsine deleted the f3 branch November 11, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants