From c298e660bd28140125f2ac6b47dff6d7c01e82ae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 4 Sep 2009 13:59:44 +1000 Subject: ldb: ensure we cancel a ldb transaction When we fail a ldbadd or ldbedit we should cancel the transaction to prevent ldb giving a warning about having a open transaction in the ldb destructor --- source4/lib/ldb/tools/ldbadd.c | 10 +++++++--- source4/lib/ldb/tools/ldbedit.c | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index 086540dfdf..f022486db8 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.c @@ -109,9 +109,13 @@ int main(int argc, const char **argv) } } - if (count != 0 && ldb_transaction_commit(ldb) != 0) { - printf("Failed to commit transaction: %s\n", ldb_errstring(ldb)); - exit(1); + if (count != 0) { + if (ldb_transaction_commit(ldb) != 0) { + printf("Failed to commit transaction: %s\n", ldb_errstring(ldb)); + exit(1); + } + } else { + ldb_transaction_cancel(ldb); } talloc_free(ldb); diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 9653eabcb9..ecadf0f61c 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -128,6 +128,7 @@ static int merge_edits(struct ldb_context *ldb, fprintf(stderr, "failed to add %s - %s\n", ldb_dn_get_linearized(msgs2[i]->dn), ldb_errstring(ldb)); + ldb_transaction_cancel(ldb); return -1; } adds++; @@ -149,6 +150,7 @@ static int merge_edits(struct ldb_context *ldb, fprintf(stderr, "failed to delete %s - %s\n", ldb_dn_get_linearized(msgs1[i]->dn), ldb_errstring(ldb)); + ldb_transaction_cancel(ldb); return -1; } deletes++; -- cgit