From: Alex Riesen Date: Wed, 29 Apr 2009 22:01:28 GMT Subject: Re: [PATCH] Workaround for ai_canonname sometimes coming back as null Message-ID: <81b0412b0904291501w501eecd4y18927018d57bdbdc@mail.gmail.com> In-Reply-To: <6B7EA51D-8412-4E6A-BA7B-156FD5B755E8@gmail.com> 2009/4/29 Augie Fackler : > On Apr 29, 2009, at 4:55 PM, Alex Riesen wrote: >> 2009/4/29 Augie Fackler : >>> >>> @@ -459,7 +459,10 @@ static void parse_extra_args(char *extra_args, int >>> buflen) >>>                               inet_ntop(AF_INET, &sin_addr->sin_addr, >>>                                         addrbuf, sizeof(addrbuf)); >>>                               free(canon_hostname); >>> -                               canon_hostname = >>> xstrdup(ai->ai_canonname); >>> +                               if (ai->ai_canonname) >>> +                                       canon_hostname = >>> xstrdup(ai->ai_canonname); >>> +                               else >>> +                                       canon_hostname = "unknown"; >> >> This last line will crash some lines down, when canon_hostname is free'd: >> > > Odd, because I'm running with that exact code and not seeing the problem. > Should I resubmit an updated patch that xstrdup's unknown into > canon_hostname? > I think you can just let canon_hostname be NULL (i.e. don't strdup it, if ai_canonname is NULL). NULL values of canon_hostname seem to be handled just fine: see path_ok and strbuf_expand_dict_cb (strbuf.c)