Skip to content

Memory leak during error handling #62

@arnimarj

Description

@arnimarj

Hi,

I believe I've found a memory leak in the handling of illegal mode arguments to dumps(). It looks like the reader object is not destructed when the mode argument is invalid:

PyErr_SetString(PyExc_ValueError, "The value of mode must be one of: "

This script seems to reproduce it:

import itertools
import resource

import bsonjs


b = b'\x15\x00\x00\x00\x10_id\x00\x01\x00\x00\x00\x10x\x00\x02\x00\x00\x00\x00'
illegal_mode = 42


for i in itertools.count():
    try:
        bsonjs.dumps(b, illlegal_mode)
    except ValueError:
        pass

    if i % 100_000 == 0:
        print('ru_maxrss', resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)

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