[PATCH:libX11 06/12] Avoid memory leak/corruption if realloc fails in XlcDL.c:resolve_object()
Matthieu Herrb
matthieu.herrb at laas.fr
Sun Aug 11 03:15:57 PDT 2013
On Sat, Aug 10, 2013 at 01:55:03PM -0700, Alan Coopersmith wrote:
> Previously, if realloc failed to increase the size, we'd still
> record that we had allocated the larger size, but the pointer
> to it would be NULL, causing future calls to be broken, and the
> previous allocation to be lost/leaked.
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Matthieu Herrb <matthieu.herrb at laas.fr>
> ---
> src/xlibi18n/XlcDL.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/src/xlibi18n/XlcDL.c b/src/xlibi18n/XlcDL.c
> index 02860a0..2bef4ac 100644
> --- a/src/xlibi18n/XlcDL.c
> +++ b/src/xlibi18n/XlcDL.c
> @@ -207,12 +207,13 @@ resolve_object(char *path, const char *lc_name)
> }
>
> if (lc_count == lc_len) {
> - lc_len += OBJECT_INC_LEN;
> - xi18n_objects_list = (XI18NObjectsList)
> - Xrealloc(xi18n_objects_list,
> - sizeof(XI18NObjectsListRec) * lc_len);
> - if (!xi18n_objects_list)
> + int new_len = lc_len + OBJECT_INC_LEN;
> + XI18NObjectsListRec *tmp = Xrealloc(xi18n_objects_list,
> + sizeof(XI18NObjectsListRec) * new_len);
> + if (tmp == NULL)
> goto done;
> + xi18n_objects_list = tmp;
> + lc_len = new_len;
> }
> n = parse_line(p, args, 6);
>
> --
> 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
--
Matthieu Herrb
More information about the xorg-devel
mailing list