Skip to content

TransactionDB.open (multi-CF overload) never releases the database path UTF chars #14893

Description

@K-ANOY

File: java/rocksjni/transaction_db.cc

Function: Java_org_rocksdb_TransactionDB_open__JJLjava_lang_String_2_3_3B_3J

The database path is acquired with GetStringUTFChars and every return path before TransactionDB::Open releases it — but none of the paths after Open do, so the string is leaked on the normal (and failure) paths.

const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);   // ~line 63
if (db_path == nullptr) {              // OOM
    return nullptr;
}
// ... column-family argument conversion ...
//     each early failure branch does:  env->ReleaseStringUTFChars(jdb_path, db_path);

const ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::TransactionDB::Open(
    *db_options, *txn_db_options, db_path, column_families, &handles, &tdb);   // ~line 114

if (s.ok()) {
    // ... builds jresults, with two `return nullptr` paths and `return jresults` ...
    return jresults;                   // db_path NOT released
} else {
    ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
    return nullptr;                    // db_path NOT released
}

A successful GetStringUTFChars must be paired with ReleaseStringUTFChars: the JVM may return a freshly allocated modified-UTF-8 copy, or pin string storage. The early argument-conversion failures correctly release db_path; all of the paths reached once TransactionDB::Open has been called (the success return jresults, its two intermediate return nullptr paths, and the Open-failure ThrowNew path) omit the release. So db_path is leaked on every normal open and on post-Open failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions