-
Notifications
You must be signed in to change notification settings - Fork 54
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
Conversation
chipitsine
commented
Oct 27, 2024
•
edited
Loading
edited
*** 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
from my view there's bigger problem when local variables are returned out of a function. |
On 27/10/2024 18:06, Ilya Shipitsin wrote:
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
It would worry me as well if that was what was happening. I think I
trust coverity less and less as time goes on.
|
@lurcher , can we merge it since it addresses leaks ? |
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? |
if NULL is returned, so con_p is leaked |
Ahh, ok, I can see that. Will fix that. |