From 661f90110924358e95cba3a35dd6c0a974bc3c26 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 5 Aug 2016 13:25:25 +1000 Subject: ctdb-tools: Close tdb database on error BUG: https://bugzilla.samba.org/show_bug.cgi?id=12121 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit c9750c821e06364cb4559f857c359c14e6799303) --- ctdb/tools/ctdb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 40a9aab89d3..50a8564a568 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -5442,17 +5442,20 @@ static int control_tfetch(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, ret = str_to_data(argv[1], strlen(argv[1]), mem_ctx, &key); if (ret != 0) { fprintf(stderr, "Failed to parse key %s\n", argv[1]); + tdb_close(tdb); return ret; } data = tdb_fetch(tdb, key); if (data.dptr == NULL) { fprintf(stderr, "No record for key %s\n", argv[1]); + tdb_close(tdb); return 1; } if (data.dsize < sizeof(struct ctdb_ltdb_header)) { fprintf(stderr, "Invalid record for key %s\n", argv[1]); + tdb_close(tdb); return 1; } @@ -5514,12 +5517,14 @@ static int control_tstore(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, ret = str_to_data(argv[1], strlen(argv[1]), mem_ctx, &key); if (ret != 0) { fprintf(stderr, "Failed to parse key %s\n", argv[1]); + tdb_close(tdb); return ret; } ret = str_to_data(argv[2], strlen(argv[2]), mem_ctx, &value); if (ret != 0) { fprintf(stderr, "Failed to parse value %s\n", argv[2]); + tdb_close(tdb); return ret; } @@ -5540,6 +5545,7 @@ static int control_tstore(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, data.dptr = talloc_size(mem_ctx, data.dsize); if (data.dptr == NULL) { fprintf(stderr, "Memory allocation error\n"); + tdb_close(tdb); return 1; } -- cgit v1.2.1