GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Memory leak possible if transaction closed before cursor. · Issue #197 · lmdbjava/lmdbjava

Memory leak possible if transaction closed before cursor. #197

New issue
Copy link
New issue
Copy link
Closed
Closed
Memory leak possible if transaction closed before cursor.#197
Copy link

Description

@danielcranford
danielcranford
opened on Jul 5, 2022
Issue body actions

lmdb closes and free()'s the memory used by MDB_cursor objects if they are created with a write transaction while cursors created with a read transaction must be manually closed/freed via mdb_cursor_close()

So far, so good. lmdbjava's Dbi.openCursor() includes documentation to this effect

   ...A cursor in a write-transaction can
   * be closed before its transaction ends, and will otherwise be closed when
   * its transaction ends. A cursor in a read-only transaction must be closed
   * explicitly, before or after its transaction ends...

lmdbjava's Cursor.close() even includes a helpful check to prevent clients from accidentally double free()ing the native cursor object by ensuring that the method throws an error if the cursor was opened with a write transaction that is now closed. Very nice.

Now for the problem: lmdbjava's Cursor owns two native resources, the MDB_cursor object and the KeyVal object which allocates memory for MDB_vals. KeyVal's native memory cannot be disposed of by the client if the transaction was writeable and closed first.

Suggest updating close to independently dispose of both native resources so that the (useful) double free protection doesn't leak the KeyVal

Activity

  1. bp-alex
    closed this as completedin bb26a83on Feb 2, 2023
  2. at055612
    added a commit that references this issue on Feb 28, 2024

    Cursor.close() must release KeyVal even if write Txn closed (fixes lm…

    This issue will close once commit bb26a83 is merged into the 'master' branch.
    bb26a83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.