From be4849448f2039bbd47013ecb306df9e8d4e1581 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 7 Dec 2014 17:10:21 +0100 Subject: [PATCH] WPrefs: fix memory leak when storing the list of texture in Appearence panel (Coverity #50112) As pointed by Coverity, the PLStrings created to store the information on the texture leak. This is due to the fact that they are created with a refCount of 1, then the PLArray in which they are placed increments that count, so at list destruction the count would return to 1 instead of 0, meaning the PLStrings won't be freed. This patch release the PLStrings once after adding them to the PLArray so the count will go back to 1, which means they will be properly freed when the PLArray will be released. Took opportunity to remove the call to WMRetainPropList on the titem-prop because it artificially increases the refCount but this is already done when adding to the PLArray. Signed-off-by: Christophe CURIS --- WPrefs.app/Appearance.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index c8cbc75e..276933bb 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -2207,11 +2207,16 @@ static void prepareForClose(_Panel * panel) /* store list of textures */ for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) { + WMPropList *pl_title, *pl_path; + item = WMGetListItem(panel->texLs, i); titem = (TextureListItem *) item->clientData; - texture = WMCreatePLArray(WMCreatePLString(titem->title), - WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL); + pl_title = WMCreatePLString(titem->title); + pl_path = WMCreatePLString(titem->path); + texture = WMCreatePLArray(pl_title, titem->prop, pl_path, NULL); + WMReleasePropList(pl_title); + WMReleasePropList(pl_path); WMAddToPLArray(textureList, texture); }