1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-19 23:22:23 +03:00

Check for out of memory when allocating sqlca.

Patch by Michael Paquier
This commit is contained in:
Michael Meskes
2015-06-15 14:21:03 +02:00
parent af0b49fc98
commit 94a484222c
7 changed files with 104 additions and 1 deletions

View File

@@ -223,6 +223,12 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
struct sqlca_t *sqlca = ECPGget_sqlca();
int sqlcode;
if (sqlca == NULL)
{
ecpg_log("out of memory");
return;
}
(void) arg; /* keep the compiler quiet */
if (sqlstate == NULL)
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
@@ -278,6 +284,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
const char **conn_keywords;
const char **conn_values;
if (sqlca == NULL)
{
ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
ecpg_free(dbname);
return false;
}
ecpg_init_sqlca(sqlca);
/*
@@ -657,6 +671,13 @@ ECPGdisconnect(int lineno, const char *connection_name)
struct sqlca_t *sqlca = ECPGget_sqlca();
struct connection *con;
if (sqlca == NULL)
{
ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
return (false);
}
#ifdef ENABLE_THREAD_SAFETY
pthread_mutex_lock(&connections_mutex);
#endif