[SERVER-4008] A memory leak per line of typed text in the shell Created: 04/Oct/11  Updated: 11/Jul/16  Resolved: 16/Nov/11

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Bug Priority: Minor - P4
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Any


Operating System: ALL
Participants:

 Description   

The linenoise() routine that shell/dbshell.cpp calls to collect typed input from the user uses strdup() to make a copy of its internal buffer's contents and returns the pointer from strdup(). The calling code acts as if this is just a pointer it can play with and not a block of memory that it now owns. It never calls free() on it. After ten lines of typing, ten small buffers have been leaked. The buffers are the minimum size required to hold the text (e.g. "a=7" is 4 bytes) so the shell would need to have a novella typed into it for this to even begin to matter. This is user input only, displayed data does not leak.



 Comments   
Comment by Tad Marshall [ 16/Nov/11 ]

Fixed in commit 8d8b272225b9a2e98f25525e0e2e7f032420388f (SERVER-4008 – don't leak memory in the shell).

Comment by auto [ 16/Nov/11 ]

Author:

{u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-4008 – don't leak memory in the shell

Track the strdup-ed (i.e. malloc-ed) strings returned by linenoise, and
free the memory when we are done with it. Free command line history
memory explicitly when we save the history to a file and stop using it.
Non-Windows versions were freeing this memory using an atexit handler,
but this handler isn't set up for Windows.
Branch: master
https://github.com/mongodb/mongo/commit/8d8b272225b9a2e98f25525e0e2e7f032420388f

Comment by Tad Marshall [ 06/Oct/11 ]

Pull request https://github.com/mongodb/mongo/pull/97 addresses this.

Generated at Thu Feb 08 03:04:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.