@@ -204,10 +204,15 @@ pqParseInput3(PGconn *conn)
204
204
conn -> result = PQmakeEmptyPGresult (conn ,
205
205
PGRES_COMMAND_OK );
206
206
if (!conn -> result )
207
- return ;
207
+ {
208
+ printfPQExpBuffer (& conn -> errorMessage ,
209
+ libpq_gettext ("out of memory" ));
210
+ pqSaveErrorResult (conn );
211
+ }
208
212
}
209
- strlcpy (conn -> result -> cmdStatus , conn -> workBuffer .data ,
210
- CMDSTATUS_LEN );
213
+ if (conn -> result )
214
+ strlcpy (conn -> result -> cmdStatus , conn -> workBuffer .data ,
215
+ CMDSTATUS_LEN );
211
216
conn -> asyncStatus = PGASYNC_READY ;
212
217
break ;
213
218
case 'E' : /* error return */
@@ -226,7 +231,11 @@ pqParseInput3(PGconn *conn)
226
231
conn -> result = PQmakeEmptyPGresult (conn ,
227
232
PGRES_EMPTY_QUERY );
228
233
if (!conn -> result )
229
- return ;
234
+ {
235
+ printfPQExpBuffer (& conn -> errorMessage ,
236
+ libpq_gettext ("out of memory" ));
237
+ pqSaveErrorResult (conn );
238
+ }
230
239
}
231
240
conn -> asyncStatus = PGASYNC_READY ;
232
241
break ;
@@ -239,7 +248,11 @@ pqParseInput3(PGconn *conn)
239
248
conn -> result = PQmakeEmptyPGresult (conn ,
240
249
PGRES_COMMAND_OK );
241
250
if (!conn -> result )
242
- return ;
251
+ {
252
+ printfPQExpBuffer (& conn -> errorMessage ,
253
+ libpq_gettext ("out of memory" ));
254
+ pqSaveErrorResult (conn );
255
+ }
243
256
}
244
257
conn -> asyncStatus = PGASYNC_READY ;
245
258
}
@@ -311,7 +324,11 @@ pqParseInput3(PGconn *conn)
311
324
conn -> result = PQmakeEmptyPGresult (conn ,
312
325
PGRES_COMMAND_OK );
313
326
if (!conn -> result )
314
- return ;
327
+ {
328
+ printfPQExpBuffer (& conn -> errorMessage ,
329
+ libpq_gettext ("out of memory" ));
330
+ pqSaveErrorResult (conn );
331
+ }
315
332
}
316
333
conn -> asyncStatus = PGASYNC_READY ;
317
334
}
@@ -736,11 +753,14 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
736
753
* Make a PGresult to hold the accumulated fields. We temporarily lie
737
754
* about the result status, so that PQmakeEmptyPGresult doesn't uselessly
738
755
* copy conn->errorMessage.
756
+ *
757
+ * NB: This allocation can fail, if you run out of memory. The rest of the
758
+ * function handles that gracefully, and we still try to set the error
759
+ * message as the connection's error message.
739
760
*/
740
761
res = PQmakeEmptyPGresult (conn , PGRES_EMPTY_QUERY );
741
- if (!res )
742
- goto fail ;
743
- res -> resultStatus = isError ? PGRES_FATAL_ERROR : PGRES_NONFATAL_ERROR ;
762
+ if (res )
763
+ res -> resultStatus = isError ? PGRES_FATAL_ERROR : PGRES_NONFATAL_ERROR ;
744
764
745
765
/*
746
766
* Read the fields and save into res.
@@ -853,20 +873,27 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
853
873
*/
854
874
if (isError )
855
875
{
856
- res -> errMsg = pqResultStrdup (res , workBuf .data );
857
- if (!res -> errMsg )
858
- goto fail ;
876
+ if (res )
877
+ res -> errMsg = pqResultStrdup (res , workBuf .data );
859
878
pqClearAsyncResult (conn );
860
879
conn -> result = res ;
861
- appendPQExpBufferStr (& conn -> errorMessage , workBuf .data );
880
+ if (PQExpBufferDataBroken (workBuf ))
881
+ printfPQExpBuffer (& conn -> errorMessage ,
882
+ libpq_gettext ("out of memory" ));
883
+ else
884
+ appendPQExpBufferStr (& conn -> errorMessage , workBuf .data );
862
885
}
863
886
else
864
887
{
865
- /* We can cheat a little here and not copy the message. */
866
- res -> errMsg = workBuf .data ;
867
- if (res -> noticeHooks .noticeRec != NULL )
868
- (* res -> noticeHooks .noticeRec ) (res -> noticeHooks .noticeRecArg , res );
869
- PQclear (res );
888
+ /* if we couldn't allocate the result set, just discard the NOTICE */
889
+ if (res )
890
+ {
891
+ /* We can cheat a little here and not copy the message. */
892
+ res -> errMsg = workBuf .data ;
893
+ if (res -> noticeHooks .noticeRec != NULL )
894
+ (* res -> noticeHooks .noticeRec ) (res -> noticeHooks .noticeRecArg , res );
895
+ PQclear (res );
896
+ }
870
897
}
871
898
872
899
termPQExpBuffer (& workBuf );
0 commit comments