Commit f1792b93 authored by Bruce Momjian's avatar Bruce Momjian

Use PQfreemem() consistently, and document its use for Notify.

Keep PQfreeNotify() around for binary compatibility.
parent 6a19c6dc
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.115 2003/03/24 18:33:52 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.116 2003/03/25 02:44:36 momjian Exp $
--> -->
<chapter id="libpq"> <chapter id="libpq">
...@@ -1049,8 +1049,7 @@ characters that are otherwise interpreted specially by the SQL parser. ...@@ -1049,8 +1049,7 @@ characters that are otherwise interpreted specially by the SQL parser.
<function>PQescapeString</> performs this operation. <function>PQescapeString</> performs this operation.
</para> </para>
<para> <para>
The The parameter <parameter>from</> points to the first character of the string that
parameter <parameter>from</> points to the first character of the string that
is to be escaped, and the <parameter>length</> parameter counts the is to be escaped, and the <parameter>length</> parameter counts the
number of characters in this string. (A terminating zero byte is number of characters in this string. (A terminating zero byte is
neither necessary nor counted.) <parameter>to</> shall point to a neither necessary nor counted.) <parameter>to</> shall point to a
...@@ -1117,7 +1116,9 @@ unsigned char *PQescapeBytea(const unsigned char *from, ...@@ -1117,7 +1116,9 @@ unsigned char *PQescapeBytea(const unsigned char *from,
<para> <para>
<function>PQescapeBytea</> returns an escaped version of the <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 The return string has all special characters replaced
so that they can be properly processed by the PostgreSQL string literal so that they can be properly processed by the PostgreSQL string literal
parser, and the <type>bytea</type> input function. A terminating zero 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); ...@@ -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 such as might be returned by <function>PQgetvalue</function> when applied to a
<type>bytea</type> column. <function>PQunescapeBytea</function> converts <type>bytea</type> column. <function>PQunescapeBytea</function> converts
this string representation into its binary representation. 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 It returns a pointer to a buffer allocated with
of the buffer in <parameter>to_length</parameter>. <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> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1161,7 +1165,9 @@ void PQfreemem(void *ptr); ...@@ -1161,7 +1165,9 @@ void PQfreemem(void *ptr);
<para> <para>
Frees memory allocated by <application>libpq</>, particularly 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 It is needed by Win32, which can not free memory across
DLL's, unless multithreaded DLL's (/MD in VC6) are used. DLL's, unless multithreaded DLL's (/MD in VC6) are used.
</para> </para>
...@@ -1926,7 +1932,7 @@ typedef struct pgNotify { ...@@ -1926,7 +1932,7 @@ typedef struct pgNotify {
} PGnotify; } PGnotify;
</synopsis> </synopsis>
After processing a <structname>PGnotify</structname> object returned by <function>PQnotifies</function>, 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> </para>
<note> <note>
...@@ -2867,7 +2873,7 @@ main() ...@@ -2867,7 +2873,7 @@ main()
fprintf(stderr, fprintf(stderr,
"ASYNC NOTIFY of '%s' from backend pid '%d' received\n", "ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
notify-&gt;relname, notify-&gt;be_pid); notify-&gt;relname, notify-&gt;be_pid);
free(notify); PQfreemem(notify);
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.61 2003/03/20 15:39:52 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.62 2003/03/25 02:44:36 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
...@@ -441,7 +441,7 @@ PrintNotifications(void) ...@@ -441,7 +441,7 @@ PrintNotifications(void)
{ {
fprintf(pset.queryFout, gettext("Asynchronous NOTIFY '%s' from backend with pid %d received.\n"), fprintf(pset.queryFout, gettext("Asynchronous NOTIFY '%s' from backend with pid %d received.\n"),
notify->relname, notify->be_pid); notify->relname, notify->be_pid);
free(notify); PQfreemem(notify);
fflush(pset.queryFout); fflush(pset.queryFout);
} }
} }
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.4 2003/03/20 15:56:50 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.5 2003/03/25 02:44:36 momjian Exp $ */
/* /*
* The aim is to get a simpler inteface to the database routines. * The aim is to get a simpler inteface to the database routines.
...@@ -1197,7 +1197,7 @@ ECPGexecute(struct statement * stmt) ...@@ -1197,7 +1197,7 @@ ECPGexecute(struct statement * stmt)
{ {
ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n", ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
stmt->lineno, notify->relname, notify->be_pid); stmt->lineno, notify->relname, notify->be_pid);
ECPGfree(notify); PQfreemem(notify);
} }
return status; return status;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.40 2003/02/01 00:22:12 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.41 2003/03/25 02:44:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -554,7 +554,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) ...@@ -554,7 +554,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags)
if (event->connid == NULL) if (event->connid == NULL)
{ {
if (event->notify) if (event->notify)
PQfreeNotify(event->notify); PQfreemem(event->notify);
return 1; return 1;
} }
...@@ -634,7 +634,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) ...@@ -634,7 +634,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags)
Tcl_Release((ClientData) event->connid); Tcl_Release((ClientData) event->connid);
if (event->notify) if (event->notify)
PQfreeNotify(event->notify); PQfreemem(event->notify);
return 1; return 1;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.127 2003/03/22 03:29:06 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.128 2003/03/25 02:44:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1577,20 +1577,6 @@ PQnotifies(PGconn *conn) ...@@ -1577,20 +1577,6 @@ PQnotifies(PGconn *conn)
return event; return event;
} }
/*
* 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. * PQgetline - gets a newline-terminated string from the backend.
* *
...@@ -2470,3 +2456,22 @@ PQsendSome(PGconn *conn) ...@@ -2470,3 +2456,22 @@ PQsendSome(PGconn *conn)
{ {
return pqSendSome(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);
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: libpq-fe.h,v 1.90 2003/03/22 03:29:06 momjian Exp $ * $Id: libpq-fe.h,v 1.91 2003/03/25 02:44:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -260,7 +260,8 @@ extern void PQfreemem(void *ptr); ...@@ -260,7 +260,8 @@ extern void PQfreemem(void *ptr);
/* Simple synchronous query */ /* Simple synchronous query */
extern PGresult *PQexec(PGconn *conn, const char *query); extern PGresult *PQexec(PGconn *conn, const char *query);
extern PGnotify *PQnotifies(PGconn *conn); 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 */ /* Interface for multiple-result or asynchronous queries */
extern int PQsendQuery(PGconn *conn, const char *query); extern int PQsendQuery(PGconn *conn, const char *query);
......
...@@ -2066,7 +2066,7 @@ pg_getnotify(pgobject * self, PyObject * args) ...@@ -2066,7 +2066,7 @@ pg_getnotify(pgobject * self, PyObject * args)
} }
PyTuple_SET_ITEM(notify_result, 1, temp); PyTuple_SET_ITEM(notify_result, 1, temp);
free(notify); PQfreemem(notify);
} }
else else
{ {
......
...@@ -98,7 +98,7 @@ main() ...@@ -98,7 +98,7 @@ main()
fprintf(stderr, fprintf(stderr,
"ASYNC NOTIFY of '%s' from backend pid '%d' received\n", "ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
notify->relname, notify->be_pid); notify->relname, notify->be_pid);
free(notify); PQfreemem(notify);
break; break;
} }
PQclear(res); PQclear(res);
......
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