Browse Source

* fixed minor logic errors in pqconnection that lead to double free (actually pqclear()). Mantis 17784 by Andrew Brunner

git-svn-id: trunk@17078 -
marco 14 years ago
parent
commit
75cdb5b244
1 changed files with 9 additions and 5 deletions
  1. 9 5
      packages/fcl-db/src/sqldb/postgres/pqconnection.pp

+ 9 - 5
packages/fcl-db/src/sqldb/postgres/pqconnection.pp

@@ -561,10 +561,11 @@ begin
       res := pqexec(tr.PGConn,pchar('deallocate prepst'+nr));
       res := pqexec(tr.PGConn,pchar('deallocate prepst'+nr));
       if (PQresultStatus(res) <> PGRES_COMMAND_OK) then
       if (PQresultStatus(res) <> PGRES_COMMAND_OK) then
         begin
         begin
+          pqclear(res);
+          DatabaseError(SErrPrepareFailed + ' (PostgreSQL: ' + PQerrorMessage(tr.PGConn) + ')',self)
+        end
+      else
         pqclear(res);
         pqclear(res);
-        DatabaseError(SErrPrepareFailed + ' (PostgreSQL: ' + PQerrorMessage(tr.PGConn) + ')',self)
-        end;
-      pqclear(res);
       end;
       end;
     FPrepared := False;
     FPrepared := False;
     end;
     end;
@@ -641,9 +642,12 @@ begin
         s := Statement;
         s := Statement;
       res := pqexec(tr.PGConn,pchar(s));
       res := pqexec(tr.PGConn,pchar(s));
       if (PQresultStatus(res) in [PGRES_COMMAND_OK,PGRES_TUPLES_OK]) then
       if (PQresultStatus(res) in [PGRES_COMMAND_OK,PGRES_TUPLES_OK]) then
-        pqclear(res);
+        begin
+          pqclear(res); 
+          res:=nil;
+        end;
       end;
       end;
-    if not (PQresultStatus(res) in [PGRES_COMMAND_OK,PGRES_TUPLES_OK]) then
+    if assigned(res) and not (PQresultStatus(res) in [PGRES_COMMAND_OK,PGRES_TUPLES_OK]) then
       begin
       begin
       s := PQerrorMessage(tr.PGConn);
       s := PQerrorMessage(tr.PGConn);
       pqclear(res);
       pqclear(res);