From 9667dc192141ab8703d4e59091f6f1a0c90339a4 Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sat, 19 Oct 2024 16:59:53 +0200 Subject: [PATCH] Handle memory allocation errors (#195) * handle memory allocation errors * handle memory allocation errors --- DriverManager/SQLDriverConnect.c | 2 ++ odbcinst/SQLCreateDataSource.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/DriverManager/SQLDriverConnect.c b/DriverManager/SQLDriverConnect.c index bbfc4c8..fd51d3f 100644 --- a/DriverManager/SQLDriverConnect.c +++ b/DriverManager/SQLDriverConnect.c @@ -465,6 +465,8 @@ struct con_pair * con_p; if ( keyword ) { con_p = malloc( sizeof( *con_p )); + if ( !con_p ) + return NULL; con_p -> keyword = keyword; con_p -> attribute = value; return con_p; diff --git a/odbcinst/SQLCreateDataSource.c b/odbcinst/SQLCreateDataSource.c index 9c41bab..58cf63b 100644 --- a/odbcinst/SQLCreateDataSource.c +++ b/odbcinst/SQLCreateDataSource.c @@ -40,6 +40,8 @@ char* _multi_string_alloc_and_copy( LPCWSTR in ) } chr = malloc( len + 2 ); + if ( !chr ) + return NULL; len = 0; while ( in[ len ] != 0 || in[ len + 1 ] != 0 ) @@ -80,6 +82,8 @@ char* _single_string_alloc_and_copy( LPCWSTR in ) } chr = malloc( ulen + 1 ); + if ( !chr ) + return NULL; len = 0; ulen = 0; @@ -127,6 +131,8 @@ char* _single_string_alloc_and_copy( LPCWSTR in ) } chr = malloc( len + 1 ); + if ( !chr ) + return NULL; len = 0; while ( in[ len ] != 0 ) @@ -157,6 +163,8 @@ SQLWCHAR* _multi_string_alloc_and_expand( LPCSTR in ) } chr = malloc(sizeof( SQLWCHAR ) * ( len + 2 )); + if ( !chr ) + return NULL; len = 0; while ( in[ len ] != 0 || in[ len + 1 ] != 0 ) @@ -186,6 +194,8 @@ SQLWCHAR* _single_string_alloc_and_expand( LPCSTR in ) } chr = malloc( sizeof( SQLWCHAR ) * ( len + 1 )); + if ( !chr ) + return NULL; len = 0; while ( in[ len ] != 0 )