Skip to content

Commit

Permalink
binding: fix memleaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 10, 2023
1 parent b19d40a commit d940132
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ struct Database {
delete db_;
db_ = NULL;
}

if (filterPolicy_ != NULL) {
delete filterPolicy_;
filterPolicy_ = NULL;
}
}

/**
Expand Down Expand Up @@ -1008,6 +1013,15 @@ struct OpenWorker final : public BaseWorker {
NAPI_METHOD(db_open) {
NAPI_ARGV(4);
NAPI_DB_CONTEXT();

napi_value callback = argv[3];

if (database->IsOpen()) {
napi_value argv = CreateError(env, "Database is already open.");
CallFunction(env, callback, 1, &argv);
NAPI_RETURN_UNDEFINED();
}

NAPI_ARGV_UTF8_NEW(location, 1);

napi_value options = argv[2];
Expand All @@ -1025,14 +1039,6 @@ NAPI_METHOD(db_open) {

database->blockCache_ = leveldb::NewLRUCache(cacheSize);

napi_value callback = argv[3];

if (database->IsOpen()) {
napi_value argv = CreateError(env, "Database is already open.");
CallFunction(env, callback, 1, &argv);
NAPI_RETURN_UNDEFINED();
}

OpenWorker* worker = new OpenWorker(env, database, callback, location,
createIfMissing, errorIfExists,
compression, writeBufferSize, blockSize,
Expand Down Expand Up @@ -1063,6 +1069,7 @@ struct CloseWorker final : public BaseWorker {

void DoFinally (napi_env env) override {
database_->closing_ = false;
BaseWorker::DoFinally(env);
}
};

Expand Down

0 comments on commit d940132

Please sign in to comment.