1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +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

@ -14,6 +14,13 @@ ecpg_raise(int line, int code, const char *sqlstate, const char *str)
{
struct sqlca_t *sqlca = ECPGget_sqlca();
if (sqlca == NULL)
{
ecpg_log("out of memory");
ECPGfree_auto_mem();
return;
}
sqlca->sqlcode = code;
strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
@ -215,6 +222,13 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
char *sqlstate;
char *message;
if (sqlca == NULL)
{
ecpg_log("out of memory");
ECPGfree_auto_mem();
return;
}
if (result)
{
sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
@ -323,6 +337,12 @@ sqlprint(void)
{
struct sqlca_t *sqlca = ECPGget_sqlca();
if (sqlca == NULL)
{
ecpg_log("out of memory");
return;
}
sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml] = '\0';
fprintf(stderr, ecpg_gettext("SQL error: %s\n"), sqlca->sqlerrm.sqlerrmc);
}