From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91880 invoked by alias); 5 Dec 2019 16:42:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 91869 invoked by uid 89); 5 Dec 2019 16:42:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 spammy=HX-Google-Smtp-Source:APXvYqz, pedro, Alves, H*r:2001 X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Dec 2019 16:42:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575564147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wgc9R9ecNs/WNUAvsrXxunyf/EeNNn4R3Vj3WidSORs=; b=OTl79zHwqvIxKkfl/Yz+T6VXZqGtZU5OUU7m/l3s2+oa/Mv0Qw6tY0eKQf99idQNsLdvoG QLjUTCmNav2diModQQY+Ugde8WrIrBBBpveq0XtTIrlThWr7dSVafn39YAiR1npRd80Vc8 DMSk8f7sBK2Ho61RJl+jWYQbxqoK79o= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-252Qw7VhNaW7nBnNnPTZuw-1; Thu, 05 Dec 2019 11:42:26 -0500 Received: by mail-wr1-f70.google.com with SMTP id u18so1774691wrn.11 for ; Thu, 05 Dec 2019 08:42:25 -0800 (PST) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id h17sm13429590wrs.18.2019.12.05.08.42.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Dec 2019 08:42:24 -0800 (PST) Subject: Re: [RFA] Fix leaks when pruning inferiors. To: Philippe Waroquiers , gdb-patches@sourceware.org References: <20191201155220.15971-1-philippe.waroquiers@skynet.be> From: Pedro Alves Message-ID: Date: Thu, 05 Dec 2019 16:42:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20191201155220.15971-1-philippe.waroquiers@skynet.be> X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-12/txt/msg00189.txt.bz2 On 12/1/19 3:52 PM, Philippe Waroquiers wrote: > Origin of the leaks is in prune_inferiors: prune_inferiors is first removing > the inferior to prune from the inferior list, then calls delete_inferior. > But delete_inferior will only really destroy the inferior when it finds > it into the inferior list. > As delete_inferior is removing the inferior to delete from the inferior list, > ensure prune_inferiors only calls delete_inferior, without touching the > inferior list. Whoops. > @@ -370,24 +370,22 @@ have_live_inferiors (void) > void > prune_inferiors (void) > { > - struct inferior *ss, **ss_link; > + struct inferior *ss, *ss_next; > > > - *ss_link = ss->next; > + ss_next = ss->next; > delete_inferior (ss); > - ss = *ss_link; > + ss = ss_next; Please declare ss_next here instead of at the top. You can omit the redundant "struct" while at it: inferior *next = ss->next; delete_inferior (ss); ss = next; OK with that change. Thanks! Pedro Alves