diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index e7c7a25..330b8da 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2242,6 +2242,7 @@ keep_going:						/* We will come back to here until there is
 				int			msgLength;
 				int			avail;
 				AuthRequest areq;
+				int			res;
 
 				/*
 				 * Scan the message from current point (note that if we find
@@ -2366,11 +2367,18 @@ keep_going:						/* We will come back to here until there is
 				{
 					if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
 					{
-						if (pqGetErrorNotice3(conn, true))
+						res = pqGetErrorNotice3(conn, true);
+						if (res == -1)
 						{
 							/* We'll come back when there is more data */
 							return PGRES_POLLING_READING;
 						}
+						else if (res == -2)
+						{
+							printfPQExpBuffer(&conn->errorMessage,
+											  libpq_gettext("out of memory\n"));
+							goto error_return;
+						}
 					}
 					else
 					{
