bugGNU nano - Bugs: bug #47003, memory leak w/position history

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #47003: memory leak w/position history

Submitter:  Mike Frysinger <vapier>
Submitted:  Thu 28 Jan 2016 10:27:35 PM UTC
   
 
Severity:  3 - Normal Status:  Fixed
Assigned to:  bens Open/Closed:  Closed

Wed 10 Feb 2016 12:34:22 PM UTC, comment #4: 

Thanks for the hint.

Fixed in SVN, r5624.

Benno Schulenberg <bens>
Group administrator
Mon 01 Feb 2016 07:35:12 AM UTC, comment #3: 

realloc() itself will not leak memory as long as you follow the rule: the pointer passed in should be replaced by the pointer returned.  so if you follow the pattern:
  foo = realloc(foo, ...)
you should be fine.

when you look at the traceback, keep in mind that the problem isn't at the last point.  that's just where the memory was allocated.  you have to back up a few points to see where the memory is actually being used.  realloc() is in the C lib, nrealloc() is in nano, so look at the caller of that.  in this case, the place to focus is get_full_path in files.c.  i think the issue is around here:
--- a/src/files.c
+++ b/src/files.c
@@ -1466,6 +1466,7 @@ char *get_full_path(const char *origpath)
    if (chdir(d_there) == -1) {
        free(d_there);
        d_there = NULL;
+free(d_here);
    } else {
        free(d_there);
 

that seems to fix the leak for me, but i haven't fully analyzed that func ... there's many code paths :x

Mike Frysinger <vapier>
Group Member
Fri 29 Jan 2016 08:50:39 PM UTC, comment #2: 

Things should be better when updating to r5600.  It maybe fixes the leak you're seeing.

I'm still seeing one, which gets "fixed" with the attached patch -- but that patch changes the behaviour: it doesn't open a buffer for any file that produces an error message, except when it is the only file given.

(file #36200)

Benno Schulenberg <bens>
Group administrator
Fri 29 Jan 2016 01:12:08 PM UTC, comment #1: 

At first I thought: how can it check position history when you use -I (that is: --ignorercfiles)?  But apparently it does.  That is a separate bug.  Will fix that first.

The leak you are seeing is in get_full_path().  I've seen it before but can't understand ho it happens, how a realloc (in files.c at line 1389) can lose memory.  A reallocation can never leak any memory, can it?

Benno Schulenberg <bens>
Group administrator
Thu 28 Jan 2016 10:27:35 PM UTC, original submission:  

i'm having a hard time coming with a reliable test case, but here's the tracebacks i'm getting.  maybe that's enough ?

this is using svn r5595

$ nano -I files/libintl-0.19.5-langinfo.patch /var/tmp/portage/intl/localename.c
<ctrl+x to close>
<ctrl+x to close>
=================================================================
==17334==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 52 byte(s) in 1 object(s) allocated from:
    #0 0x7f134dc0736a in realloc (/usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/libasan.so.2+0x9d36a)
    #1 0x455db4 in nrealloc .../nano/src/utils.c:400
    #2 0x415939 in get_full_path .../nano/src/files.c:1389
    #3 0x413a70 in open_file .../nano/src/files.c:958
    #4 0x411328 in open_buffer .../nano/src/files.c:429
    #5 0x433e67 in main .../nano/src/nano.c:2621
    #6 0x7f134cf295ef in __libc_start_main (/lib64/libc.so.6+0x205ef)

Direct leak of 52 byte(s) in 1 object(s) allocated from:
    #0 0x7f134dc0736a in realloc (/usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/libasan.so.2+0x9d36a)
    #1 0x455db4 in nrealloc .../nano/src/utils.c:400
    #2 0x415939 in get_full_path .../nano/src/files.c:1389
    #3 0x41d8bc in check_poshistory .../nano/src/files.c:3234
    #4 0x433f18 in main .../nano/src/nano.c:2634
    #5 0x7f134cf295ef in __libc_start_main (/lib64/libc.so.6+0x205ef)

SUMMARY: AddressSanitizer: 104 byte(s) leaked in 2 allocation(s).

Mike Frysinger <vapier>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #36200:  avoid-a-fullpath-leak.patch added by bens (501B - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by prongs
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by vapier (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-02-13 bens Open/ClosedOpen Closed
    2016-02-10 bens StatusNone Fixed
    2016-02-02 prongs Carbon-Copy- Added prongs
    2016-02-02 prongs Carbon-CopyRemoved prongs -
    2016-02-02 prongs Carbon-Copy- Added prongs
    2016-01-29 bens Attached File- Added avoid-a-fullpath-leak.patch, #36200
    2016-01-29 bens Assigned toNone bens

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code