diff options
author | Bruce Momjian | 2003-03-25 02:44:36 +0000 |
---|---|---|
committer | Bruce Momjian | 2003-03-25 02:44:36 +0000 |
commit | 380e16adb9908c898c03480e4c6e728f0a5cb91b (patch) | |
tree | 934bec688fd368435c9a40c6846561162bfdb169 | |
parent | 283d5bb8331b0808a858b2d66b73bdf81798a5d2 (diff) |
Use PQfreemem() consistently, and document its use for Notify.
Keep PQfreeNotify() around for binary compatibility.
-rw-r--r-- | doc/src/sgml/libpq.sgml | 22 | ||||
-rw-r--r-- | src/bin/psql/common.c | 2 | ||||
-rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 2 | ||||
-rw-r--r-- | src/interfaces/libpgtcl/pgtclId.c | 4 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 33 | ||||
-rw-r--r-- | src/interfaces/libpq/libpq-fe.h | 3 | ||||
-rw-r--r-- | src/interfaces/python/pgmodule.c | 2 | ||||
-rw-r--r-- | src/test/examples/testlibpq2.c | 2 |
8 files changed, 41 insertions, 29 deletions
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index e770fe4af9..a623186549 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1049,8 +1049,7 @@ characters that are otherwise interpreted specially by the SQL parser. <function>PQescapeString</> performs this operation. </para> <para> -The -parameter <parameter>from</> points to the first character of the string that +The parameter <parameter>from</> points to the first character of the string that is to be escaped, and the <parameter>length</> parameter counts the number of characters in this string. (A terminating zero byte is neither necessary nor counted.) <parameter>to</> shall point to a @@ -1117,7 +1116,9 @@ unsigned char *PQescapeBytea(const unsigned char *from, <para> <function>PQescapeBytea</> returns an escaped version of the - <parameter>from</parameter> parameter binary string in memory allocated with <function>malloc()</>. + <parameter>from</parameter> parameter binary string in memory + allocated with <function>malloc()</>, and must be freed using + <function>PQfreemem()</>. The return string has all special characters replaced so that they can be properly processed by the PostgreSQL string literal parser, and the <type>bytea</type> input function. A terminating zero @@ -1143,8 +1144,11 @@ unsigned char *PQunescapeBytea(const unsigned char *from, size_t *to_length); such as might be returned by <function>PQgetvalue</function> when applied to a <type>bytea</type> column. <function>PQunescapeBytea</function> converts this string representation into its binary representation. - It returns a pointer to a buffer allocated with <function>malloc()</function>, or null on error, and puts the size - of the buffer in <parameter>to_length</parameter>. + It returns a pointer to a buffer allocated with + <function>malloc()</function>, or null on error, and puts the size of + the buffer in <parameter>to_length</parameter>. The memory must be + freed using <function>PQfreemem()</>. + </para> </listitem> </varlistentry> @@ -1161,7 +1165,9 @@ void PQfreemem(void *ptr); <para> Frees memory allocated by <application>libpq</>, particularly - <function>PQescapeBytea</function> and <function>PQunescapeBytea</function>. + <function>PQescapeBytea</function>, + <function>PQunescapeBytea</function>, + and <function>PQnotifies</function>. It is needed by Win32, which can not free memory across DLL's, unless multithreaded DLL's (/MD in VC6) are used. </para> @@ -1926,7 +1932,7 @@ typedef struct pgNotify { } PGnotify; </synopsis> After processing a <structname>PGnotify</structname> object returned by <function>PQnotifies</function>, -be sure to free it with <function>free()</function> to avoid a memory leak. +be sure to free it with <function>PQfreemem()</function>. </para> <note> @@ -2867,7 +2873,7 @@ main() fprintf(stderr, "ASYNC NOTIFY of '%s' from backend pid '%d' received\n", notify->relname, notify->be_pid); - free(notify); + PQfreemem(notify); } } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 7a18bf1004..6412913622 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -441,7 +441,7 @@ PrintNotifications(void) { fprintf(pset.queryFout, gettext("Asynchronous NOTIFY '%s' from backend with pid %d received.\n"), notify->relname, notify->be_pid); - free(notify); + PQfreemem(notify); fflush(pset.queryFout); } } diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 54632c9bb3..a899fb0fe4 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1197,7 +1197,7 @@ ECPGexecute(struct statement * stmt) { ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n", stmt->lineno, notify->relname, notify->be_pid); - ECPGfree(notify); + PQfreemem(notify); } return status; diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index 35e26bd02e..b2add66191 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -554,7 +554,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) if (event->connid == NULL) { if (event->notify) - PQfreeNotify(event->notify); + PQfreemem(event->notify); return 1; } @@ -634,7 +634,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) Tcl_Release((ClientData) event->connid); if (event->notify) - PQfreeNotify(event->notify); + PQfreemem(event->notify); return 1; } diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 3a586130f2..3aa4226ae0 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -1578,20 +1578,6 @@ PQnotifies(PGconn *conn) } /* - * PQfreeNotify - free's the memory associated with a PGnotify - * - * This function is needed on Windows when using libpq.dll and - * for example libpgtcl.dll: All memory allocated inside a dll - * should be freed in the context of the same dll. - * - */ -void -PQfreeNotify(PGnotify *notify) -{ - free(notify); -} - -/* * PQgetline - gets a newline-terminated string from the backend. * * Chiefly here so that applications can use "COPY <rel> to stdout" @@ -2470,3 +2456,22 @@ PQsendSome(PGconn *conn) { return pqSendSome(conn); } + +/* + * PQfreeNotify - free's the memory associated with a PGnotify + * + * This function is here only for binary backward compatibility. + * New code should use PQfreemem(). A macro will automatically map + * calls to PQfreemem. It should be removed in the future. bjm 2003-03-24 + */ + +#undef PQfreeNotify +void PQfreeNotify(PGnotify *notify); + +void +PQfreeNotify(PGnotify *notify) +{ + PQfreemem(notify); +} + + diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 92327d5b90..b4fa408204 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -260,7 +260,8 @@ extern void PQfreemem(void *ptr); /* Simple synchronous query */ extern PGresult *PQexec(PGconn *conn, const char *query); extern PGnotify *PQnotifies(PGconn *conn); -extern void PQfreeNotify(PGnotify *notify); +/* Exists for backward compatibility. bjm 2003-03-24 */ +#define PQfreeNotify(ptr) PQfreemem(ptr) /* Interface for multiple-result or asynchronous queries */ extern int PQsendQuery(PGconn *conn, const char *query); diff --git a/src/interfaces/python/pgmodule.c b/src/interfaces/python/pgmodule.c index f0194ed0e1..b659c99759 100644 --- a/src/interfaces/python/pgmodule.c +++ b/src/interfaces/python/pgmodule.c @@ -2066,7 +2066,7 @@ pg_getnotify(pgobject * self, PyObject * args) } PyTuple_SET_ITEM(notify_result, 1, temp); - free(notify); + PQfreemem(notify); } else { diff --git a/src/test/examples/testlibpq2.c b/src/test/examples/testlibpq2.c index 059e39102e..8f5a1ec3ab 100644 --- a/src/test/examples/testlibpq2.c +++ b/src/test/examples/testlibpq2.c @@ -98,7 +98,7 @@ main() fprintf(stderr, "ASYNC NOTIFY of '%s' from backend pid '%d' received\n", notify->relname, notify->be_pid); - free(notify); + PQfreemem(notify); break; } PQclear(res); |