Commit b84788de authored by Neil Conway's avatar Neil Conway

Minor cleanup of libpq/LO examples: fix some memory leaks, update a comment

or two.
parent a94edb4c
/* /*
* testlibpq.c * testlibpq.c
* *
* Test the C version of LIBPQ, the POSTGRES frontend library. * Test the C version of libpq, the PostgreSQL frontend library.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -92,8 +92,8 @@ main(int argc, char **argv) ...@@ -92,8 +92,8 @@ main(int argc, char **argv)
} }
/* /*
* should PQclear PGresult whenever it is no longer needed to avoid * make sure to PQclear() a PGresult whenever it is no longer
* memory leaks * needed to avoid memory leaks
*/ */
PQclear(res1); PQclear(res1);
...@@ -106,7 +106,7 @@ main(int argc, char **argv) ...@@ -106,7 +106,7 @@ main(int argc, char **argv)
{ {
fprintf(stderr, "DECLARE CURSOR command failed\n"); fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res1); PQclear(res1);
exit_nicely(conn1, NULL); exit_nicely(conn1, conn2);
} }
PQclear(res1); PQclear(res1);
...@@ -115,7 +115,7 @@ main(int argc, char **argv) ...@@ -115,7 +115,7 @@ main(int argc, char **argv)
{ {
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n"); fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
PQclear(res1); PQclear(res1);
exit_nicely(conn1, NULL); exit_nicely(conn1, conn2);
} }
/* first, print out the attribute names */ /* first, print out the attribute names */
...@@ -142,10 +142,10 @@ main(int argc, char **argv) ...@@ -142,10 +142,10 @@ main(int argc, char **argv)
res1 = PQexec(conn1, "END"); res1 = PQexec(conn1, "END");
PQclear(res1); PQclear(res1);
/* close the connection to the database and cleanup */ /* close the connections to the database and cleanup */
PQfinish(conn1); PQfinish(conn1);
PQfinish(conn2);
/* fclose(debug); */ /* fclose(debug); */
return 0; /* Though PQfinish(conn1) has called return 0;
* exit(1) */
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/test/examples/testlo.c,v 1.22 2004/08/29 04:13:12 momjian Exp $ * $PostgreSQL: pgsql/src/test/examples/testlo.c,v 1.23 2004/09/22 05:12:45 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -99,6 +99,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len) ...@@ -99,6 +99,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len)
if (nbytes <= 0) if (nbytes <= 0)
break; /* no more data? */ break; /* no more data? */
} }
free(buf);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
lo_close(conn, lobj_fd); lo_close(conn, lobj_fd);
} }
...@@ -134,6 +135,7 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len) ...@@ -134,6 +135,7 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len)
break; break;
} }
} }
free(buf);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
lo_close(conn, lobj_fd); lo_close(conn, lobj_fd);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment