ldb_tdb: Clean up index records on ltdb_index_add_new() failure.
authorAndrew Bartlett <abartlet@samba.org>
Fri, 8 Sep 2017 06:07:51 +0000 (18:07 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:24 +0000 (21:20 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index 7925433cf1bbd79d2c667bf36abbb1651841cb9e..16b7fa0026384575acbaa6e54f6ea15e512cc513 100644 (file)
@@ -2038,10 +2038,29 @@ int ltdb_index_add_new(struct ldb_module *module,
 
        ret = ltdb_index_add_all(module, ltdb, msg);
        if (ret != LDB_SUCCESS) {
+               /*
+                * Because we can't trust the caller to be doing
+                * transactions properly, clean up any index for this
+                * entry rather than relying on a transaction
+                * cleanup
+                */
+
+               ltdb_index_delete(module, msg);
                return ret;
        }
 
-       return ltdb_index_onelevel(module, msg, 1);
+       ret = ltdb_index_onelevel(module, msg, 1);
+       if (ret != LDB_SUCCESS) {
+               /*
+                * Because we can't trust the caller to be doing
+                * transactions properly, clean up any index for this
+                * entry rather than relying on a transaction
+                * cleanup
+                */
+               ltdb_index_delete(module, msg);
+               return ret;
+       }
+       return ret;
 }