[Xcb] [Bug 22353] New: found a memroy leak in file

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Thu Jun 18 14:02:00 PDT 2009


http://bugs.freedesktop.org/show_bug.cgi?id=22353

           Summary: found a memroy leak in file
           Product: XCB
           Version: 1.1
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: medium
         Component: Library
        AssignedTo: xcb at lists.freedesktop.org
        ReportedBy: ettl.martin at gmx.de
         QAContact: xcb at lists.freedesktop.org


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


-- 
Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the Xcb mailing list