Skip to content

Commit

Permalink
handle memory allocation errors (#196)
Browse files Browse the repository at this point in the history
* handle memory allocation errors

* handle memory allocation failures
  • Loading branch information
chipitsine authored Oct 21, 2024
1 parent 9667dc1 commit b3ce35a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cur/SQLExecDirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,23 @@ SQLRETURN get_column_names( CLHSTMT cl_statement )

cl_statement -> column_names = malloc( sizeof(char *)
* cl_statement -> column_count );
if ( !cl_statement->column_names )
return SQL_ERROR;

cl_statement -> data_type = malloc( sizeof( SQLSMALLINT )
* cl_statement -> column_count );
if ( !cl_statement->data_type )
return SQL_ERROR;

cl_statement -> column_size = malloc( sizeof( SQLULEN )
* cl_statement -> column_count );
if ( !cl_statement->column_size )
return SQL_ERROR;

cl_statement -> decimal_digits = malloc( sizeof( SQLSMALLINT )
* cl_statement -> column_count );
if ( !cl_statement->decimal_digits )
return SQL_ERROR;

for ( i = 1; i <= cl_statement -> column_count; i ++ )
{
Expand Down
2 changes: 2 additions & 0 deletions ini/iniObjectInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ int iniObjectInsert( HINI hIni, char *pszObject )

/* CREATE OBJECT STRUCT */
hObject = malloc( sizeof(INIOBJECT) );
if ( !hObject )
return INI_ERROR;
hIni->hCurProperty = NULL;
hObject->hFirstProperty = NULL;
hObject->hLastProperty = NULL;
Expand Down
4 changes: 4 additions & 0 deletions ini/iniOpen.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, c

/* INIT STATEMENT */
*hIni = malloc( sizeof(INI) );
if ( !*hIni )
return INI_ERROR;
if ( pszFileName && pszFileName != STDINFILE )
strncpy((*hIni)->szFileName, pszFileName, ODBC_FILENAME_MAX );
else if ( pszFileName == STDINFILE )
Expand Down Expand Up @@ -363,6 +365,8 @@ int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, c

/* INIT STATEMENT */
*hIni = malloc( sizeof(INI) );
if ( !*hIni )
return INI_ERROR;
if ( pszFileName && pszFileName != STDINFILE )
strncpy((*hIni)->szFileName, pszFileName, ODBC_FILENAME_MAX );
else if ( pszFileName == STDINFILE )
Expand Down
2 changes: 2 additions & 0 deletions log/logOpen.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ int logOpen( HLOG *phLog, char *pszProgramName, char *pszLogFile, long nMaxMsgs

/* LOG STRUCT */
*phLog = malloc( sizeof(LOG) );
if ( !*phLog )
return LOG_ERROR;
(*phLog)->nMaxMsgs = nMaxMsgs;
(*phLog)->hMessages = lstOpen();
(*phLog)->bOn = 0;
Expand Down

0 comments on commit b3ce35a

Please sign in to comment.