pickledb icon indicating copy to clipboard operation
pickledb copied to clipboard

bug: reuse of exception causing memory leak

Open j123b567 opened this issue 5 years ago • 0 comments

In the code, there is

key_string_error = TypeError('Key/name must be a string!')

which create exception on place, where it does not occur.

And later use

raise self.key_string_error

Which append new tracebak to existing one in this exception object so the traceback grows without bounds.

It is later imposible to debug the code, because the traceback can be very long. It also introduces memory leak, because key_string_error is class variable and is never freed.

Expected solution:

Raise new instance of TypeError('Key/name must be a string!') every time, or create new exception type with predefined message for this.

Example code to reproduce the issue:

import pickledb
import traceback

db = pickledb.load('example.db', False)
for i in range(100):
    try:
        db.set({}, "")
    except TypeError:
        print("***********************************")
        traceback.print_exc()

j123b567 avatar Jun 16 '20 12:06 j123b567