[PATCH] Avoid memory leak on failure to allocate name during resolving

Roman Arutyunyan arut at nginx.com
Mon Jun 19 11:32:41 UTC 2017


Hello Bart,

On Mon, Jun 19, 2017 at 08:00:37AM +0200, Bart Warmerdam wrote:
> 
> # HG changeset patch
> # User Bart Warmerdam <bartw at xs4all.nl>
> # Date 1497851445 -7200
> #      Mon Jun 19 07:50:45 2017 +0200
> # Branch memleak_resolve_name
> # Node ID dd8c5ef0483cf0abe6f9f88b4bb9ba681aec7be4
> # Parent  d1816a2696de8c2faa1cd913a151e5f62a8620f3
> Avoid leak on error allocating name
> 
> diff -r d1816a2696de -r dd8c5ef0483c src/core/ngx_resolver.c
> --- a/src/core/ngx_resolver.c   Fri Jun 16 18:15:58 2017 +0300
> +++ b/src/core/ngx_resolver.c   Mon Jun 19 07:50:45 2017 +0200
> @@ -443,7 +443,7 @@
> 
>          name.data = ngx_resolver_alloc(r, name.len);
>          if (name.data == NULL) {
> -            return NGX_ERROR;
> +            goto resolve_error;
>          }
> 
>          if (slen == ctx->service.len) {
> @@ -481,6 +481,7 @@
>          ngx_resolver_free(r, ctx->event);
>      }
> 
> +resolve_error:
>      ngx_resolver_free(r, ctx);
> 
>      return NGX_ERROR;

Thanks!

Committed with minor changes.

-- 
Roman Arutyunyan


More information about the nginx-devel mailing list