[python-bsonjs] Fix memory leak in dump() and dumps()

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: python-bsonjs
    • None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      User arnimarj opened ihttps://github.com/mongodb-labs/python-bsonjs/issues/62:

      "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: https://github.com/mongodb-labs/python-bsonjs/blob/e0f5088f03ef2526bb839659342309d234d4922f/bsonjs/bsonjs.c#L50

      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)
      

      We should fix the memory leak and make a release.

            Assignee:
            Steve Silvester
            Reporter:
            Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: