src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 298
8f5c556120a5
parent 297
14cd7137a3a8
child 304
33911d44111d
--- a/src/server/plugins/postgresql/vfs.c	Mon Apr 18 17:31:45 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Tue Apr 19 12:32:22 2022 +0200
@@ -472,12 +472,17 @@
 {
     // create transaction savepoint
     PGresult *result = PQexec(pg->connection, "savepoint del_res;");
-    if(PQresultStatus(result) != PGRES_COMMAND_OK) {
+    ExecStatusType execStatus = PQresultStatus(result);
+    PQclear(result);
+    if(execStatus != PGRES_COMMAND_OK) {
         return 1;
     }
     
     if(oid > 0) {
         if(lo_unlink(pg->connection, oid) != 1) {
+            // restore savepoint
+            result = PQexec(pg->connection, "rollback to savepoint del_res;");
+            PQclear(result);
             return 1; // error
         }
     }
@@ -496,14 +501,21 @@
             NULL,
             0);    // 0: result in text format
       
+    execStatus = PQresultStatus(result);
+    PQclear(result); 
     int ret = 0;
-    if(PQresultStatus(result) != PGRES_COMMAND_OK) {
+    
+    if(execStatus != PGRES_COMMAND_OK) {
         ret = 1;
         // restore savepoint
         result = PQexec(pg->connection, "rollback to savepoint del_res;");
         PQclear(result);
+    } else {
+        // we don't need the savepoint anymore
+        result = PQexec(pg->connection, "release savepoint del_res;");
+        PQclear(result);
     }
-    PQclear(result); 
+    
     return ret;
 }
 

mercurial