On Sat, 31 May 2014 19:58:40 +0200
Christophe <[email protected]> wrote:

> From: Christophe CURIS <[email protected]>
> 
> As pointed by Coverity, it is possible to dereference the NULL
> pointer in the function 'browseForFile'.
> This should have been reported by the compiler ("possible use of
> uninitialised variable") but the assignation of a default value to the
> variable 'lPtr' hides this, but as the default value is not a good
> one then the code could crash.
> This patch removes the default value, so we may have some info from
> the compiler and handles the case smoothly.
> 
> It also fixes a potential memory leak pointed also by Coverity in the
> case where the string returned by WMGetFilePanelFileName would be a 0
> length non-null string.
> 
> Signed-off-by: Christophe CURIS <[email protected]>
> ---
>  WPrefs.app/Paths.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/WPrefs.app/Paths.c b/WPrefs.app/Paths.c
> index 86f27a4..101b797 100644
> --- a/WPrefs.app/Paths.c
> +++ b/WPrefs.app/Paths.c
> @@ -149,22 +149,24 @@ static void browseForFile(WMWidget * w, void
> *data) len--;
>                       }
>                       if (len > 0) {
> -                             WMList *lPtr = NULL;
> +                             WMList *lPtr;
>                               int i;
>  
>                               if (w == panel->icoaB)
>                                       lPtr = panel->icoL;
>                               else if (w == panel->pixaB)
>                                       lPtr = panel->pixL;
> +                             else
> +                                     goto error_unknow_widget;
>  
>                               i = WMGetListSelectedItemRow(lPtr);
>                               if (i >= 0)
>                                       i++;
>                               addPathToList(lPtr, i, str);
>                               WMSetListBottomPosition(lPtr,
> WMGetListNumberOfRows(lPtr)); -
> -                             wfree(str);
>                       }
> +             error_unknow_widget:
> +                     wfree(str);
>               }
>       }
>  }

error_unknow_widget -> error_unknown_widget ?


-- 
To unsubscribe, send mail to [email protected].

Reply via email to