aboutsummaryrefslogtreecommitdiff
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:21:03 +0200
commit94a484222caece19e381a6941b8d826027ac2e75 (patch)
tree70cdda36851d1249ed1ac9c6db0b59b7b1a8041f /src/interfaces/ecpg/ecpglib/misc.c
parentaf0b49fc98cb3494d1e444a4f5c3364627a3ed5f (diff)
downloadpostgresql-94a484222caece19e381a6941b8d826027ac2e75.tar.gz
postgresql-94a484222caece19e381a6941b8d826027ac2e75.zip
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 2e622607477..a13aa0a9da8 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);
@@ -524,6 +535,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);