walter harms <[email protected]> writes: > Am 21.05.2015 14:55, schrieb Eirik Byrkjeflot Anonsen: >> Signed-off-by: Eirik Byrkjeflot Anonsen <[email protected]> >> --- >> xprop.c | 10 ++++++++-- >> 1 file changed, 8 insertions(+), 2 deletions(-) >> >> diff --git a/xprop.c b/xprop.c >> index ba23b87..4576db6 100644 >> --- a/xprop.c >> +++ b/xprop.c >> @@ -1442,9 +1442,15 @@ Get_Window_Property_Data_And_Type (Atom atom, >> unsigned long nitems; >> unsigned long nbytes; >> unsigned long bytes_after; >> - unsigned char *prop; >> + static unsigned char *prop = NULL; >> int status; >> - >> + >> + if (prop) >> + { >> + XFree(prop); >> + prop = NULL; >> + } >> + > > > let free() handle prop==NULL > > but in general the caller is responsible to free the memory >
The problem is that the caller does not know whether this memory was allocated by X, by malloc() or not actually allocated at all. If I remember correctly, all three cases exist in the code. So only the code in this function knows that the correct thing to do is to call XFree(). eirik > re, > wh > >> status = XGetWindowProperty(dpy, target_win, atom, 0, (max_len+3)/4, >> False, AnyPropertyType, &actual_type, >> &actual_format, &nitems, &bytes_after, > _______________________________________________ > [email protected]: X.Org development > Archives: http://lists.x.org/archives/xorg-devel > Info: http://lists.x.org/mailman/listinfo/xorg-devel _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
