From 607cd930d5095f914aa6d3f23d29a41cedcf92af Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Sat, 3 Oct 1998 02:33:51 +0000 Subject: Changes from Michael Meskes: Check strdup calls for out of memory. Set library version to 2.6.2 Synced preproc.y and keywords.c with gram.y and keywords.c yet again. Set version to 2.4.3 --- src/interfaces/ecpg/lib/ecpglib.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/interfaces/ecpg/lib/ecpglib.c') diff --git a/src/interfaces/ecpg/lib/ecpglib.c b/src/interfaces/ecpg/lib/ecpglib.c index 4b7ed87c1ff..f982d5103cb 100644 --- a/src/interfaces/ecpg/lib/ecpglib.c +++ b/src/interfaces/ecpg/lib/ecpglib.c @@ -148,6 +148,22 @@ ecpg_alloc(long size, int lineno) return (new); } +static char * +ecpg_strdup(const char *string, int lineno) +{ + char *new = strdup(string); + + if (!new) + { + ECPGfinish(actual_connection); + ECPGlog("out of memory\n"); + register_error(ECPG_OUT_OF_MEMORY, "out of memory in line %d", lineno); + return NULL; + } + + return (new); +} + /* This function returns a newly malloced string that has the ' and \ in the argument quoted with \. */ @@ -246,7 +262,7 @@ ECPGexecute(struct statement * stmt) memcpy((char *) &sqlca, (char *) &sqlca_init, sizeof(sqlca)); - copiedquery = strdup(stmt->command); + copiedquery = ecpg_strdup(stmt->command, stmt->lineno); /* * Now, if the type is one of the fill in types then we take the @@ -914,9 +930,9 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd /* add connection to our list */ if (connection_name != NULL) - this->name = strdup(connection_name); + this->name = ecpg_strdup(connection_name, lineno); else - this->name = strdup(dbname); + this->name = ecpg_strdup(dbname, lineno); if (all_connections == NULL) this->next = NULL; -- cgit v1.2.3