From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 75D2E386F809 for ; Wed, 3 Jun 2020 08:40:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 75D2E386F809 Received: by mail-pg1-x52b.google.com with SMTP id u5so1294943pgn.5 for ; Wed, 03 Jun 2020 01:40:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=0Whe+Ty2bJGOyhk372W/lkUVTXDAZieyBg7PucDBgEc=; b=txzcfvgUFjalnuUKx2ENFKh/ove0H4D7Snopk1hFtethVXH+Cb+8Opmh+Jivw69jSv Wmug+sMXlbxut8kPWU+sisNvap/dkCZKmQ5af3XpeSzl+mH1PeX0a02tGPlew8dtOUK7 3fMu7VSh65IDtWaI7KMSfWcdX8xcK8GDLBB0YL+Eu++gbqIdU4PGsAoz5EP/P2Ht04/K /nE/M8PGvdgUsnZ9ATl3oJgJpCNeKPUfOMPJtgKsG+sAz6ogmAlTA1upx5z8qFjFFzcP AzQhWukTT7+YhILgbWtI1KVOHZBXnvr7R87BbaNqimLtIHAOryqzlPY9yrH08SrLRbyF +16g== X-Gm-Message-State: AOAM531v+mqwGfXejJfx3IkZewSiNLnux/2DQVNxbffPycWH/oUmCGy0 DGoff1ugxkXb4/XBa9IVcYBPe6vaVRk= X-Google-Smtp-Source: ABdhPJyMcZfzq6GJcTgYyHV1BQ3Cp+NH9hK5qqfi9Q4w0BFMjNCA+cufopY/tPMCtMHD9i9btRdXgA== X-Received: by 2002:a17:90a:b78e:: with SMTP id m14mr4205264pjr.114.1591173629301; Wed, 03 Jun 2020 01:40:29 -0700 (PDT) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id s197sm1359139pfc.188.2020.06.03.01.40.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 01:40:28 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 3D54680699; Wed, 3 Jun 2020 18:10:25 +0930 (ACST) Date: Wed, 3 Jun 2020 18:10:25 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PR26069, strip/objcopy memory leaks Message-ID: <20200603084025.GG29024@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jun 2020 08:40:31 -0000 PR 26069 * objcopy.c (copy_relocations_in_section): Free relpp on error. Don't accidentally free isection->orelocation. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 5760d06a85..3866c7f458 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4294,6 +4294,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg) status = 1; bfd_nonfatal_message (NULL, ibfd, isection, _("relocation count is negative")); + free (relpp); return; } } @@ -4318,7 +4319,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg) temp_relpp [temp_relcount++] = relpp [i]; } relcount = temp_relcount; - if (isection->orelocation == NULL) + if (relpp != isection->orelocation) free (relpp); relpp = temp_relpp; } @@ -4327,7 +4328,8 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg) if (relcount == 0) { osection->flags &= ~SEC_RELOC; - free (relpp); + if (relpp != isection->orelocation) + free (relpp); } } } -- Alan Modra Australia Development Lab, IBM