PQmakeEmptyPGresult() will return NULL if malloc() fails for required
PGresult struct.
Index: doc/src/sgml/libpq.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/libpq.sgml,v
retrieving revision 1.184
diff -u -c -r1.184 libpq.sgml
*** doc/src/sgml/libpq.sgml	10 Jun 2005 03:02:01 -0000	1.184
--- doc/src/sgml/libpq.sgml	10 Jun 2005 06:45:28 -0000
***************
*** 1657,1663 ****
  
  <para>
  This is <application>libpq</>'s internal function to allocate and initialize an empty
! <structname>PGresult</structname> object.  It is exported because some applications find it
  useful to generate result objects (particularly objects with error
  status) themselves.  If <parameter>conn</parameter> is not null and <parameter>status</> indicates an error,
  the current error message of the specified connection is copied into the <structname>PGresult</structname>.
--- 1657,1664 ----
  
  <para>
  This is <application>libpq</>'s internal function to allocate and initialize an empty
! <structname>PGresult</structname> object. Function will return NULL if required memory
! couldn't be allocated. It is exported because some applications find it
  useful to generate result objects (particularly objects with error
  status) themselves.  If <parameter>conn</parameter> is not null and <parameter>status</> indicates an error,
  the current error message of the specified connection is copied into the <structname>PGresult</structname>.
Index: src/interfaces/libpq/fe-exec.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v
retrieving revision 1.139
diff -u -c -r1.139 fe-exec.c
*** src/interfaces/libpq/fe-exec.c	21 Jun 2003 21:51:34 -0000	1.139
--- src/interfaces/libpq/fe-exec.c	10 Jun 2005 06:45:30 -0000
***************
*** 130,135 ****
--- 130,137 ----
  	PGresult   *result;
  
  	result = (PGresult *) malloc(sizeof(PGresult));
+ 	if (!result)
+ 		return NULL;
  
  	result->ntups = 0;
  	result->numAttributes = 0;
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply via email to