Hi
A friend and I hit this a while ago but we got no useful response to a fix from
upstream either, so fixing it is good with me.
However, I don't think your fix is correct.
We want to call freeaddrinfo only if the getaddrinfo call succeeds (returns 0).
If it doesn't return 0 (error), res should never be non-NULL. So your check
will never be true and will leak if cancelled after getaddrinfo is called (when
error == 0, res != NULL).
It should be sufficient to check for one of either error == 0 or res != NULL (I
would favour the latter but I guess the author intended the former).
On Wed, Nov 18, 2009 at 07:51:56PM -0800, Aaron Stellman wrote:
> Tried contacting upstream, but no response from there. This patch
> prevents NULL being passed to freeaddrinfo()
>
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/net/btpd/Makefile,v
> retrieving revision 1.6
> diff -N -u -p Makefile
> --- Makefile 12 Feb 2009 12:27:35 -0000 1.6
> +++ Makefile 19 Nov 2009 03:51:30 -0000
> @@ -3,6 +3,7 @@
> COMMENT= BitTorrent Protocol Daemon
>
> DISTNAME= btpd-0.15
> +PKGNAME= ${DISTNAME}p0
> CATEGORIES= net
>
> MAINTAINER= Martin Cronier <[email protected]>
> Index: patches/patch-btpd_addrinfo_c
> ===================================================================
> RCS file: patches/patch-btpd_addrinfo_c
> diff -N -u -p patches/patch-btpd_addrinfo_c
> --- /dev/null 18 Nov 2009 20:51:30 -0000
> +++ patches/patch-btpd_addrinfo_c 19 Nov 2009 03:51:30 -0000
> @@ -0,0 +1,12 @@
> +$OpenBSD$
> +--- btpd/addrinfo.c.orig Wed Aug 5 12:18:57 2009
> ++++ btpd/addrinfo.c Wed Aug 5 12:19:42 2009
> +@@ -52,7 +52,7 @@ addrinfo_td_cb(void *arg)
> + struct ai_ctx *ctx = arg;
> + if (!ctx->cancel)
> + ctx->cb(ctx->arg, ctx->error, ctx->res);
> +- else if (ctx->error != 0)
> ++ else if ((ctx->error != 0) && (ctx->res != NULL))
> + freeaddrinfo(ctx->res);
> + free(ctx);
> + }
>