Bug 19768

Summary: cairo/util/malloc-stats.c:90: Memory leak: name
Product: cairo Reporter: dvice_null
Component: generalAssignee: Carl Worth <cworth>
Status: RESOLVED WONTFIX QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium    
Version: 1.9.1   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description dvice_null 2009-01-27 13:53:00 UTC
From latest git

In file cairo/util/malloc-stats.c:90
Variable "name" is leaking memory I think. strdup allocates memory, but later if p is not null, the pointer location is moved, which would make it unlikely for the caller to be able to release the memory correctly. 

I didn't follow the execution path to see what is eventually done to the returned value, is it freed with free() or not and not even sure what happens if you call free() for a pointer that is in the middle of allocated memory. 

	name = strdup (strings[0]);

	p = strchr (name, '\t');
	if (p)
		name = p + 1;

	free (strings);

	return name;
}

This bug was found using cppcheck: http://cppcheck.wiki.sourceforge.net/
Comment 1 Chris Wilson 2009-01-27 14:04:15 UTC
The strdup()ed memory is kept until process termination. I'm inclined to keep the lightweight malloc profiler as simple as possible (and no simpler).

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.