Bug 22353 - found a memroy leak in file
Summary: found a memroy leak in file
Status: RESOLVED NOTABUG
Alias: None
Product: xorg
Classification: Unclassified
Component: Lib/Xlib (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: xcb mailing list dummy
QA Contact: xcb mailing list dummy
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-18 14:01 UTC by ettlmartin
Modified: 2009-06-30 09:19 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description ettlmartin 2009-06-18 14:01:59 UTC
Hello,

i checked the sources of libX11-1.1.5 with static code analyis tool cpppcheck. It brought up an issue in file 
libX11-1.1.5/src/xlibi18n/lcUniConv/8bit_tab_to_h.c at line 129. 

Cppcheck has the following output:

[libX11-1.1.5/src/xlibi18n/lcUniConv/8bit_tab_to_h.c:129]: (error) Memory leak: fname

Take a look at the sourcecode:

    FILE* f;

    {
      char* fname = malloc(strlen(directory)+strlen(filename)+1);
      strcpy(fname,directory); strcat(fname,filename);
      f = fopen(fname,"w");
      if (f == NULL)
        exit(1);
    }

// ....

Indeed the memory of fname is not freed!
A possible way out is following code:



    FILE* f;

    {
      char* fname = malloc(strlen(directory)+strlen(filename)+1);
      strcpy(fname,directory); strcat(fname,filename);
      f = fopen(fname,"w");
      if (f == NULL) 
      {
         free(fname);
         exit(1);
      }
    }


Best regards

Ettl Martin
Comment 1 Peter Harris 2009-06-18 15:06:50 UTC
Bug in cppcheck: exit() frees everything.
Comment 2 ettlmartin 2009-06-18 23:38:45 UTC
Ok, i see. Nether the less, it's bad programming style. Everybody who allocates memory should free it!! But, it's just my opinion.

Best regards

Ettl Marin


-------- Original-Nachricht --------
> Datum: Thu, 18 Jun 2009 15:06:50 -0700 (PDT)
> Von: bugzilla-daemon@freedesktop.org
> An: ettl.martin@gmx.de
> Betreff: [Bug 22353] found a memroy leak in file

> http://bugs.freedesktop.org/show_bug.cgi?id=22353
> 
> 
> Peter Harris <peter.harris@hummingbird.com> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|NEW                         |RESOLVED
>          Resolution|                            |NOTABUG
> 
> 
> 
> 
> --- Comment #1 from Peter Harris <peter.harris@hummingbird.com> 
> 2009-06-18 15:06:50 PST ---
> Bug in cppcheck: exit() frees everything.
> 
> 
> -- 
> Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.

Comment 3 martin 2009-06-28 08:36:21 UTC
It is bad programming style for sure. If this was x11 library code it would be a big problem (not just the leak but the very existence of an exit() call in library code is smelly) but this particular source file is a small utility program used to generate other source code so it might not be worth the effort. However, please keep up your work in hunting for memory leaks in libx11; they are particularly nasty in library code since all X apps suffer from them.
Comment 4 Jamey Sharp 2009-06-30 09:19:54 UTC
Just for the record, this wasn't an XCB-related bug, either. Reassigning to xorg and leaving resolved.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.