summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/connect.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2015-06-15 14:21:03 +0200
committerMichael Meskes <meskes@postgresql.org>2015-06-15 14:23:21 +0200
commit6ab1a53dd595098390d2412e4f6d390f206b82dc (patch)
tree19da7824cd8582de68cfccbe27f7f3488fed8a77 /src/interfaces/ecpg/ecpglib/connect.c
parenta38f08bb9de6064fe3f42d273bd60a96adceb4bd (diff)
Check for out of memory when allocating sqlca.
Patch by Michael Paquier
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/connect.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index d255c5d8f88..f3571becadb 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -216,6 +216,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;
@@ -277,6 +283,14 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
*options = NULL,
*connect_string = NULL;
+ 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);
/*
@@ -556,6 +570,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