Skip to content

Commit b84788d

Browse files
author
Neil Conway
committed
Minor cleanup of libpq/LO examples: fix some memory leaks, update a comment
or two.
1 parent a94edb4 commit b84788d

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/test/examples/testlibpq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* testlibpq.c
33
*
4-
* Test the C version of LIBPQ, the POSTGRES frontend library.
4+
* Test the C version of libpq, the PostgreSQL frontend library.
55
*/
66
#include <stdio.h>
77
#include <stdlib.h>

src/test/examples/testlibpq4.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ main(int argc, char **argv)
9292
}
9393

9494
/*
95-
* should PQclear PGresult whenever it is no longer needed to avoid
96-
* memory leaks
95+
* make sure to PQclear() a PGresult whenever it is no longer
96+
* needed to avoid memory leaks
9797
*/
9898
PQclear(res1);
9999

@@ -106,7 +106,7 @@ main(int argc, char **argv)
106106
{
107107
fprintf(stderr, "DECLARE CURSOR command failed\n");
108108
PQclear(res1);
109-
exit_nicely(conn1, NULL);
109+
exit_nicely(conn1, conn2);
110110
}
111111
PQclear(res1);
112112

@@ -115,7 +115,7 @@ main(int argc, char **argv)
115115
{
116116
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
117117
PQclear(res1);
118-
exit_nicely(conn1, NULL);
118+
exit_nicely(conn1, conn2);
119119
}
120120

121121
/* first, print out the attribute names */
@@ -142,10 +142,10 @@ main(int argc, char **argv)
142142
res1 = PQexec(conn1, "END");
143143
PQclear(res1);
144144

145-
/* close the connection to the database and cleanup */
145+
/* close the connections to the database and cleanup */
146146
PQfinish(conn1);
147+
PQfinish(conn2);
147148

148149
/* fclose(debug); */
149-
return 0; /* Though PQfinish(conn1) has called
150-
* exit(1) */
150+
return 0;
151151
}

src/test/examples/testlo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/test/examples/testlo.c,v 1.22 2004/08/29 04:13:12 momjian Exp $
11+
* $PostgreSQL: pgsql/src/test/examples/testlo.c,v 1.23 2004/09/22 05:12:45 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -99,6 +99,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len)
9999
if (nbytes <= 0)
100100
break; /* no more data? */
101101
}
102+
free(buf);
102103
fprintf(stderr, "\n");
103104
lo_close(conn, lobj_fd);
104105
}
@@ -134,6 +135,7 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len)
134135
break;
135136
}
136137
}
138+
free(buf);
137139
fprintf(stderr, "\n");
138140
lo_close(conn, lobj_fd);
139141
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy