Merge pull request #6711 from sfc-gh-anoyes/anoyes/tenant-test-fixes

Fix a few memory issues found by ASAN
This commit is contained in:
A.J. Beamon 2022-03-29 13:43:35 -07:00 committed by GitHub
commit 8a68781150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View File

@ -138,6 +138,12 @@ Tenant::Tenant(FDBDatabase* db, const uint8_t* name, int name_length) {
} }
} }
Tenant::~Tenant() {
if (tenant != nullptr) {
fdb_tenant_destroy(tenant);
}
}
// Transaction // Transaction
Transaction::Transaction(FDBDatabase* db) { Transaction::Transaction(FDBDatabase* db) {
if (fdb_error_t err = fdb_database_create_transaction(db, &tr_)) { if (fdb_error_t err = fdb_database_create_transaction(db, &tr_)) {
@ -146,7 +152,7 @@ Transaction::Transaction(FDBDatabase* db) {
} }
} }
Transaction::Transaction(Tenant tenant) { Transaction::Transaction(Tenant& tenant) {
if (fdb_error_t err = fdb_tenant_create_transaction(tenant.tenant, &tr_)) { if (fdb_error_t err = fdb_tenant_create_transaction(tenant.tenant, &tr_)) {
std::cerr << fdb_get_error(err) << std::endl; std::cerr << fdb_get_error(err) << std::endl;
std::abort(); std::abort();

View File

@ -206,6 +206,11 @@ public:
class Tenant final { class Tenant final {
public: public:
Tenant(FDBDatabase* db, const uint8_t* name, int name_length); Tenant(FDBDatabase* db, const uint8_t* name, int name_length);
~Tenant();
Tenant(const Tenant&) = delete;
Tenant& operator=(const Tenant&) = delete;
Tenant(Tenant&&) = delete;
Tenant& operator=(Tenant&&) = delete;
private: private:
friend class Transaction; friend class Transaction;
@ -219,7 +224,7 @@ class Transaction final {
public: public:
// Given an FDBDatabase, initializes a new transaction. // Given an FDBDatabase, initializes a new transaction.
Transaction(FDBDatabase* db); Transaction(FDBDatabase* db);
Transaction(Tenant tenant); Transaction(Tenant& tenant);
~Transaction(); ~Transaction();
// Wrapper around fdb_transaction_reset. // Wrapper around fdb_transaction_reset.

View File

@ -51,7 +51,9 @@ ACTOR Future<bool> createTenantCommandActor(Reference<IDatabase> db, std::vector
tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES); tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
try { try {
if (!doneExistenceCheck) { if (!doneExistenceCheck) {
Optional<Value> existingTenant = wait(safeThreadFutureToFuture(tr->get(tenantNameKey))); // Hold the reference to the standalone's memory
state ThreadFuture<Optional<Value>> existingTenantFuture = tr->get(tenantNameKey);
Optional<Value> existingTenant = wait(safeThreadFutureToFuture(existingTenantFuture));
if (existingTenant.present()) { if (existingTenant.present()) {
throw tenant_already_exists(); throw tenant_already_exists();
} }
@ -96,7 +98,9 @@ ACTOR Future<bool> deleteTenantCommandActor(Reference<IDatabase> db, std::vector
tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES); tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
try { try {
if (!doneExistenceCheck) { if (!doneExistenceCheck) {
Optional<Value> existingTenant = wait(safeThreadFutureToFuture(tr->get(tenantNameKey))); // Hold the reference to the standalone's memory
state ThreadFuture<Optional<Value>> existingTenantFuture = tr->get(tenantNameKey);
Optional<Value> existingTenant = wait(safeThreadFutureToFuture(existingTenantFuture));
if (!existingTenant.present()) { if (!existingTenant.present()) {
throw tenant_not_found(); throw tenant_not_found();
} }
@ -163,8 +167,10 @@ ACTOR Future<bool> listTenantsCommandActor(Reference<IDatabase> db, std::vector<
loop { loop {
try { try {
RangeResult tenants = wait(safeThreadFutureToFuture( // Hold the reference to the standalone's memory
tr->getRange(firstGreaterOrEqual(beginTenantKey), firstGreaterOrEqual(endTenantKey), limit))); state ThreadFuture<RangeResult> kvsFuture =
tr->getRange(firstGreaterOrEqual(beginTenantKey), firstGreaterOrEqual(endTenantKey), limit);
RangeResult tenants = wait(safeThreadFutureToFuture(kvsFuture));
if (tenants.empty()) { if (tenants.empty()) {
if (tokens.size() == 1) { if (tokens.size() == 1) {
@ -213,7 +219,9 @@ ACTOR Future<bool> getTenantCommandActor(Reference<IDatabase> db, std::vector<St
loop { loop {
try { try {
Optional<Value> tenant = wait(safeThreadFutureToFuture(tr->get(tenantNameKey))); // Hold the reference to the standalone's memory
state ThreadFuture<Optional<Value>> tenantFuture = tr->get(tenantNameKey);
Optional<Value> tenant = wait(safeThreadFutureToFuture(tenantFuture));
if (!tenant.present()) { if (!tenant.present()) {
throw tenant_not_found(); throw tenant_not_found();
} }