Use PQfreemem() consistently, and document its use for Notify.
authorBruce Momjian
Tue, 25 Mar 2003 02:44:36 +0000 (02:44 +0000)
committerBruce Momjian
Tue, 25 Mar 2003 02:44:36 +0000 (02:44 +0000)
Keep PQfreeNotify() around for binary compatibility.

doc/src/sgml/libpq.sgml
src/bin/psql/common.c
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/libpgtcl/pgtclId.c
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/libpq-fe.h
src/interfaces/python/pgmodule.c
src/test/examples/testlibpq2.c

index 43ec1a9bf6a34b4f47f26d71f6826b94a770a0b5..40d4f1fee9f9fdc5862cc7b1adf883663068d68e 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -1049,8 +1049,7 @@ characters that are otherwise interpreted specially by the SQL parser.
 PQescapeString performs this operation.
 
 
-The
-parameter from points to the first character of the string that
+The parameter from points to the first character of the string that
 is to be escaped, and the length parameter counts the
 number of characters in this string.  (A terminating zero byte is
 neither necessary nor counted.)  to shall point to a
@@ -1117,7 +1116,9 @@ unsigned char *PQescapeBytea(const unsigned char *from,
 
   
    PQescapeBytea returns an escaped version of the
-   from parameter binary string in memory allocated with malloc().
+   from parameter binary string in memory
+   allocated with malloc(), and must be freed using
+   PQfreemem().
    The return string has all special characters replaced
    so that they can be properly processed by the PostgreSQL string literal
    parser, and the bytea 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 PQgetvalue when applied to a
    bytea column. PQunescapeBytea converts
    this string representation into its binary representation.
-   It returns a pointer to a buffer allocated with malloc(), or null on error, and puts the size
-   of the buffer in to_length.
+   It returns a pointer to a buffer allocated with
+   malloc(), or null on error, and puts the size of
+   the buffer in to_length. The memory must be
+   freed using PQfreemem().
+
   
   
   
@@ -1161,7 +1165,9 @@ void PQfreemem(void *ptr);
 
 
    Frees memory allocated by libpq, particularly
-   PQescapeBytea and PQunescapeBytea.
+   PQescapeBytea,
+   PQunescapeBytea,
+   and PQnotifies.
    It is needed by Win32, which can not free memory across
    DLL's, unless multithreaded DLL's (/MD in VC6) are used.
   
@@ -1926,7 +1932,7 @@ typedef struct pgNotify {
 } PGnotify;
 
 After processing a PGnotify object returned by PQnotifies,
-be sure to free it with free() to avoid a memory leak.
+be sure to free it with PQfreemem().
 
 
 
@@ -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);
         }
     }
 
index 9f493a4d1300e9fca709333e93617a0012013b5f..ba6e2954481c73e50b638b61b65ed3fff1b1f0ae 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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 "common.h"
@@ -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);
    }
 }
index 0fdd925a09c30140d0aec5a64ddcb4beb5713965..24a46edc4150da3661e7244c1dfab8f22ce394b6 100644 (file)
@@ -1,4 +1,4 @@
-/* $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.
@@ -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;
index c1b32866d4137decc4f973b4ec158f63de2296ab..7467b0241223d7e266155d1cd82e560634427b3c 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * 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)
    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;
 }
index 5b8a6d3ef04de6478a8ecddbe33469c857106f2d..9e86b3aa6726c0ae1e8bbe2e36bd88d849ae995a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
    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.
  *
@@ -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);
+}
+
+
index ce9132deb4bffa499cb356705d86ed610c95501f..d32b6fdeea37f7123ac3f8d1e2b97107bdf86189 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * 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);
 /* 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);
index f0194ed0e17b945ca60295a5b22543a7bd02d240..b659c99759e97738ad705e914a51d727a3ad2d0d 100644 (file)
@@ -2066,7 +2066,7 @@ pg_getnotify(pgobject * self, PyObject * args)
        }
 
        PyTuple_SET_ITEM(notify_result, 1, temp);
-       free(notify);
+       PQfreemem(notify);
    }
    else
    {
index 059e39102e2ec7b2ffc9d0a1069f686a8850f081..8f5a1ec3abbaabf372c83e104be788a10d8409de 100644 (file)
@@ -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);