diff options
author | Neil Conway <neilc@samurai.com> | 2005-06-12 00:00:21 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2005-06-12 00:00:21 +0000 |
commit | 72a5db15d190121e63126055824f38dd062428be (patch) | |
tree | 82e9ec66aca79f9e213da819b3231664a6363b63 /src/interfaces/libpq/fe-exec.c | |
parent | 2f1210629cf357fd0b6035e47ef10f240c82f6d5 (diff) | |
download | postgresql-72a5db15d190121e63126055824f38dd062428be.tar.gz postgresql-72a5db15d190121e63126055824f38dd062428be.zip |
libpq was not consistently checking for memory allocation failures. This
patch adds missing checks to the call sites of malloc(), strdup(),
PQmakeEmptyPGresult(), pqResultAlloc(), and pqResultStrdup(), and updates
the documentation. Per original report from Volkan Yazici about
PQmakeEmptyPGresult() not checking for malloc() failure.
Diffstat (limited to 'src/interfaces/libpq/fe-exec.c')
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 1a01a4c627c..64ef9cd4282 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.168 2005/06/09 20:01:16 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.169 2005/06/12 00:00:21 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -134,6 +134,8 @@ PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status) PGresult *result; result = (PGresult *) malloc(sizeof(PGresult)); + if (!result) + return NULL; result->ntups = 0; result->numAttributes = 0; @@ -453,7 +455,7 @@ pqPrepareAsyncResult(PGconn *conn) * a trailing newline, and should not be more than one line). */ void -pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) +pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt, ...) { char msgBuf[1024]; va_list args; @@ -470,6 +472,8 @@ pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) /* Make a PGresult to pass to the notice receiver */ res = PQmakeEmptyPGresult(NULL, PGRES_NONFATAL_ERROR); + if (!res) + return; res->noticeHooks = *hooks; /* @@ -480,15 +484,19 @@ pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) /* XXX should provide a SQLSTATE too? */ /* - * Result text is always just the primary message + newline. + * Result text is always just the primary message + newline. If we + * can't allocate it, don't bother invoking the receiver. */ res->errMsg = (char *) pqResultAlloc(res, strlen(msgBuf) + 2, FALSE); - sprintf(res->errMsg, "%s\n", msgBuf); + if (res->errMsg) + { + sprintf(res->errMsg, "%s\n", msgBuf); - /* - * Pass to receiver, then free it. - */ - (*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg, res); + /* + * Pass to receiver, then free it. + */ + (*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg, res); + } PQclear(res); } @@ -1127,8 +1135,9 @@ PQisBusy(PGconn *conn) /* * PQgetResult - * Get the next PGresult produced by a query. - * Returns NULL if and only if no query work remains. + * Get the next PGresult produced by a query. Returns NULL if no + * query work remains or an error has occurred (e.g. out of + * memory). */ PGresult * |