Skip to content

Memory leak in sqlite3.Connection.load_extension() #154109

Description

@MonadChains

Bug report

Bug description:

Public issue regarding the issue found by @sushi-gif. Here is a summary of the discussion:
The function sqlite3.Connection.load_extension() has a minor memory leak that occurs when SQLite throws an error while loading an extension (sqlite3_load_extension). According to SQLite specifications, the buffer of the error message must be freed manually after use. The attached PR fixes the issue.

Reproduction code:

import sqlite3

cx = sqlite3.connect(":memory:")
cx.enable_load_extension(True)

for _ in range(1000000):
    try:
        cx.load_extension("does_not_exist")
    except sqlite3.Error:
        pass

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions