From f43a3f42d30096ccbd12e9db4b4f345749f224be Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sun, 27 Oct 2024 19:02:33 +0100 Subject: [PATCH] fix potential leak found by coverity *** 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 --- DriverManager/SQLDriverConnect.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DriverManager/SQLDriverConnect.c b/DriverManager/SQLDriverConnect.c index fd51d3f..39fe83e 100644 --- a/DriverManager/SQLDriverConnect.c +++ b/DriverManager/SQLDriverConnect.c @@ -466,7 +466,12 @@ struct con_pair * con_p; { con_p = malloc( sizeof( *con_p )); if ( !con_p ) + { + free(keyword); + if ( value ) + free(value); return NULL; + } con_p -> keyword = keyword; con_p -> attribute = value; return con_p;