[libpostgresql-jdbc-java] 01/07: Every execution of a Statement clears the warning chain from the previous execution. This was causing a memory leak by endlessly chaining warnings together that should have been discarded. Report and analysis by Albe Laurenz.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:15 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_0_313
in repository libpostgresql-jdbc-java.

commit 6452452581fb2d8983df6ab64ee867d2283d5046
Author: Kris Jurka <books at ejurka.com>
Date:   Fri Aug 12 18:22:31 2005 +0000

    Every execution of a Statement clears the warning chain from the
    previous execution.  This was causing a memory leak by endlessly
    chaining warnings together that should have been discarded.
    Report and analysis by Albe Laurenz.
---
 org/postgresql/jdbc2/AbstractJdbc2Statement.java |  8 +++++++-
 org/postgresql/test/jdbc2/BatchExecuteTest.java  | 14 +++++++++++++-
 org/postgresql/test/jdbc2/StatementTest.java     | 15 +++++++++++++--
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index f018cd2..04847f1 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.6 2005/05/08 23:52:00 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.7 2005/06/08 16:21:01 davec Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -356,6 +356,9 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
     }
 
     protected void execute(Query queryToExecute, ParameterList queryParameters, int flags) throws SQLException {
+        // Every statement execution clears any previous warnings.
+        clearWarnings();
+
         // Close any existing resultsets associated with this statement.
         while (firstUnclosedResult != null)
         {
@@ -2412,6 +2415,9 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
     {
         checkClosed();
 
+        // Every statement execution clears any previous warnings.
+	clearWarnings();
+
         if (batchStatements == null || batchStatements.isEmpty())
             return new int[0];
 
diff --git a/org/postgresql/test/jdbc2/BatchExecuteTest.java b/org/postgresql/test/jdbc2/BatchExecuteTest.java
index 6e93ec5..bd1eddb 100644
--- a/org/postgresql/test/jdbc2/BatchExecuteTest.java
+++ b/org/postgresql/test/jdbc2/BatchExecuteTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java,v 1.11 2004/11/09 08:54:00 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/BatchExecuteTest.java,v 1.12 2005/01/11 08:25:48 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -241,4 +241,16 @@ public class BatchExecuteTest extends TestCase
 
         stmt.close();
     }
+
+    public void testWarningsAreCleared() throws SQLException
+    {
+        Statement stmt = con.createStatement();
+        stmt.addBatch("CREATE TEMP TABLE unused (a int primary key)");
+        stmt.executeBatch();
+        // Execute an empty batch to clear warnings.
+        stmt.executeBatch();
+        assertNull(stmt.getWarnings());
+        stmt.close();
+    }
+
 }
diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java
index 44ad2e6..781dc26 100644
--- a/org/postgresql/test/jdbc2/StatementTest.java
+++ b/org/postgresql/test/jdbc2/StatementTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.14 2005/01/18 21:33:18 oliver Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.15 2005/01/27 11:30:48 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -306,5 +306,16 @@ public class StatementTest extends TestCase
             assertEquals(TestUtil.getDatabase(),rs.getString(1));
         }
     }
-    
+
+    public void testWarningsAreCleared() throws SQLException
+    {
+        Statement stmt = con.createStatement();
+        // Will generate a NOTICE: for primary key index creation
+        stmt.execute("CREATE TEMP TABLE unused (a int primary key)");
+        stmt.executeQuery("SELECT 1");
+	// Executing another query should clear the warning from the first one.
+        assertNull(stmt.getWarnings());
+        stmt.close();
+    }
+
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list