On Mon, Jun 18, 2018 at 04:37:32PM +0200, Jan Schreiber wrote:
> Hi,
> 
> this patch closes potential memory leaks in the mandoc memory wrapper
> functions and follows the examples in the manpages.
> 

These are not leaks since mandoc exits via err(3) immediately after an
allocation failure. Which is the whole point of these wrappers I
imagine.

> 
> diff --git mandoc_aux.c mandoc_aux.c
> index 7c23ecfdd01..dbfb83faffc 100644
> --- mandoc_aux.c
> +++ mandoc_aux.c
> @@ -66,27 +66,43 @@ mandoc_malloc(size_t size)
>  void *
>  mandoc_realloc(void *ptr, size_t size)
>  {
> -     ptr = realloc(ptr, size);
> -     if (ptr == NULL)
> +     void    *nptr;
> +
> +     nptr = realloc(ptr, size);
> +     if (nptr == NULL) {
> +             free(ptr);
>               err((int)MANDOCLEVEL_SYSERR, NULL);
> +     }
> +
> +     ptr = nptr;
>       return ptr;
>  }
>  
>  void *
>  mandoc_reallocarray(void *ptr, size_t num, size_t size)
>  {
> -     ptr = reallocarray(ptr, num, size);
> -     if (ptr == NULL)
> +     void    *nptr;
> +
> +     nptr = reallocarray(ptr, num, size);
> +     if (nptr == NULL) {
> +             free(ptr);
>               err((int)MANDOCLEVEL_SYSERR, NULL);
> +     }
> +     ptr = nptr;
>       return ptr;
>  }
>  
>  void *
>  mandoc_recallocarray(void *ptr, size_t oldnum, size_t num, size_t size)
>  {
> -     ptr = recallocarray(ptr, oldnum, num, size);
> -     if (ptr == NULL)
> +     void    *nptr;
> +
> +     nptr = recallocarray(ptr, oldnum, num, size);
> +     if (nptr == NULL) {
> +             free(nptr);
>               err((int)MANDOCLEVEL_SYSERR, NULL);
> +     }
> +     ptr = nptr;
>       return ptr;
>  }
>  
> 

-- 
I'm not entirely sure you are real.

Reply via email to