From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C873B3857C4A for ; Thu, 17 Mar 2022 04:42:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C873B3857C4A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-322-dVtCyLZfNHGXk5t1zhCuNA-1; Thu, 17 Mar 2022 00:42:48 -0400 X-MC-Unique: dVtCyLZfNHGXk5t1zhCuNA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 99389802809; Thu, 17 Mar 2022 04:42:48 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-4.rdu2.redhat.com [10.10.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 855CF4B8D46; Thu, 17 Mar 2022 04:42:48 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 22H4glS01744998; Thu, 17 Mar 2022 00:42:47 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v2 08/12] gaih_inet: separate nss lookup loop into its own function In-Reply-To: <20220314094835.1159523-9-siddhesh@sourceware.org> (message from Siddhesh Poyarekar via Libc-alpha on Mon, 14 Mar 2022 15:18:31 +0530) Date: Thu, 17 Mar 2022 00:42:47 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 04:42:58 -0000 Siddhesh Poyarekar via Libc-alpha writes: > --- One memory leak needs fixing... > +static void > +gaih_result_reset (struct gaih_result *res) > +{ > + if (res->free_at) > + free (res->at); > + free (res->canon); > + memset (res, 0, sizeof (*res)); > +} (I think this fixes the problem in [07/12] ;) > -/* Convert struct hostent to a list of struct gaih_addrtuple objects. > - h_name is not copied, and the struct hostent object must not be > - deallocated prematurely. *RESULT must be NULL or a pointer to a > - linked-list. The new addresses are appended at the end. */ > +/* Convert struct hostent to a list of struct gaih_addrtuple objects. h_name > + is not copied, and the struct hostent object must not be deallocated > + prematurely. *RESULT must be NULL or a pointer to a linked-list. The new > + addresses are appended at the end. */ no changes, ok. > static bool > -convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, > - int family, > - struct hostent *h, > - struct gaih_addrtuple **result) > +convert_hostent_to_gaih_addrtuple (const struct addrinfo *req, int family, > + struct hostent *h, struct gaih_result *res) Ok. > - struct gaih_addrtuple *array = *result; > + struct gaih_addrtuple *array = res->at; Ok. > - array = realloc (*result, (old + count) * sizeof (*array)); > + array = res->at = realloc (res->at, (old + count) * sizeof (*array)); > > if (array == NULL) > return false; > > - *result = array; This is not the same - if realloc fails, the original res->at is lost and can no longer be free'd. > + res->got_ipv6 = family == AF_INET6; > + res->free_at = true; Ok. > - goto free_and_return; \ > + goto out; \ Ok. > - goto free_and_return; \ > + goto out; \ Ok. > - if (!convert_hostent_to_gaih_addrtuple (req, _family, &th, &addrmem)) \ > + if (!convert_hostent_to_gaih_addrtuple (req, _family, &th, res)) \ Ok. > - goto free_and_return; \ > + goto out; \ Ok. > - *pat = addrmem; \ > \ > - if (localcanon != NULL && res.canon == NULL) \ > + if (localcanon != NULL && res->canon == NULL) \ Ok. > - goto free_and_return; \ > + goto out; \ Ok. > - res.canon = canonbuf; \ > + res->canon = canonbuf; \ Ok. > - if (_family == AF_INET6 && *pat != NULL) \ > - res.got_ipv6 = true; \ Ok. > +static int > +get_nss_addresses (const char *name, const struct addrinfo *req, > + struct scratch_buffer *tmpbuf, struct gaih_result *res) > +{ > + . . . > +} Moved, ok. > - if (!convert_hostent_to_gaih_addrtuple (req, AF_INET, h, &res->at)) > + if (!convert_hostent_to_gaih_addrtuple (req, AF_INET, h, res)) > return -EAI_MEMORY; Ok. > - int no_data = 0; > - int no_inet6_data = 0; > - . . . > - } Moved, ok. > + if ((result = get_nss_addresses (name, req, tmpbuf, &res)) != 0) > + goto free_and_return; > + else if (res.at != NULL) > + goto process_list; Ok. > - process_list: > - if (res.at == NULL) > - { > - result = -EAI_NONAME; > - goto free_and_return; > - } > + /* None of the lookups worked, so name not found. */ > + result = -EAI_NONAME; > + goto free_and_return; Ok. > > +process_list: > { > /* Set up the canonical name if we need it. */ > if ((result = process_canonname (req, orig_name, &res)) != 0) Ok.