summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/misc.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/misc.c
parenta38f08bb9de6064fe3f42d273bd60a96adceb4bd (diff)
Check for out of memory when allocating sqlca.
Patch by Michael Paquier
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/misc.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/misc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index ef7e63470cd..08e76198019 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -106,6 +106,13 @@ ecpg_init(const struct connection * con, const char *connection_name, const int
{
struct sqlca_t *sqlca = ECPGget_sqlca();
+ if (sqlca == NULL)
+ {
+ ecpg_raise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY,
+ NULL);
+ return (false);
+ }
+
ecpg_init_sqlca(sqlca);
if (con == NULL)
{
@@ -143,6 +150,8 @@ ECPGget_sqlca(void)
if (sqlca == NULL)
{
sqlca = malloc(sizeof(struct sqlca_t));
+ if (sqlca == NULL)
+ return NULL;
ecpg_init_sqlca(sqlca);
pthread_setspecific(sqlca_key, sqlca);
}
@@ -286,9 +295,11 @@ ecpg_log(const char *format,...)
va_end(ap);
/* dump out internal sqlca variables */
- if (ecpg_internal_regression_mode)
+ if (ecpg_internal_regression_mode && sqlca != NULL)
+ {
fprintf(debugstream, "[NO_PID]: sqlca: code: %ld, state: %s\n",
sqlca->sqlcode, sqlca->sqlstate);
+ }
fflush(debugstream);
@@ -529,6 +540,13 @@ ECPGset_var(int number, void *pointer, int lineno)
{
struct sqlca_t *sqlca = ECPGget_sqlca();
+ if (sqlca == NULL)
+ {
+ ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,
+ ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
+ return;
+ }
+
sqlca->sqlcode = ECPG_OUT_OF_MEMORY;
strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate));
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "out of memory on line %d", lineno);