[PATCH:iceauth] Free old argv array if realloc fails to enlarge it
Peter Hutterer
peter.hutterer at who-t.net
Sun Dec 8 15:52:57 PST 2013
On Sun, Dec 08, 2013 at 12:55:57PM -0800, Alan Coopersmith wrote:
> Found by cppcheck:
> [app/iceauth/process.c:302]: (error) Common realloc mistake:
> 'argv' nulled but not freed upon failure
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
> ---
> process.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/process.c b/process.c
> index 09cb7ef..6f7396d 100644
> --- a/process.c
> +++ b/process.c
> @@ -298,9 +298,13 @@ static char **split_into_words ( /* argvify string */
> savec = *src;
> *src = '\0';
> if (cur == total) {
> + char **prevargv = argv;
> total += WORDSTOALLOC;
> argv = (char **) realloc (argv, total * sizeof (char *));
> - if (!argv) return NULL;
> + if (!argv) {
> + free (prevargv);
> + return NULL;
> + }
> }
> argv[cur++] = jword;
> if (savec) src++; /* if not last on line advance */
> --
> 1.7.9.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list