From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 7CA1B3858D3C for ; Sun, 27 Aug 2023 04:49:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CA1B3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bf1935f6c2so14555575ad.1 for ; Sat, 26 Aug 2023 21:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693111741; x=1693716541; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=ngazLLWPzsvgA4QEaIbUedMmHGpb1MgOso/JWBy4u9o=; b=Bcud/XIYNmeeOj+JRc2jYjK13EmCsboVM+R1+mXTb7DJbkOczxuPuNIl4s3hQqrMxH zAYiXcSK1+fcvFUTqCrtlEZoHiw/WXfnCRJTP4/lkYVntNVmDVQrUPqYLodhfCzk96uT 7j6WT3QHeVBu+ZDH93QDNpiCvZ7883F/3BD9iHz00M0Uc8VJrUKcM7yM6yJSd7RgcTxD mT3axbKzsbEcQwzQMyTYTXsyGxm/GlaPFE9ZIOKKOnkW1Hc6mb7NN14jLE/3BVIdXhxL hQCol80ffG7xhfPLSJk70d+tdoymrTDE2Pp8x8tLDp3BLPK85A7rkrLnAe0ApQyB7wgq dEIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693111741; x=1693716541; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ngazLLWPzsvgA4QEaIbUedMmHGpb1MgOso/JWBy4u9o=; b=FMVATxrjY04wnfbEiyxK8WfgCo+bFm9u9zXHI2L0fuLGlBHkKYqGVuIukDcD5CKuG5 PnbTHMIGbJSGs9DCHqz7QNaS+FXNeUkwgvbKtzQMbsTKt8MuFtRW2UolDZyYBivfbShv I5rPCCtnOSbUwE83u19wLby8qU/dqRNjZel0ELBfjOv0Q/1oa4wJ0uxsRkMPcCRBmXTT OVTyMgKMIyU51nZZ53j5lTWIkkRUlgPXrBd1F8445ArQh77G/3EN1esxcteUHWqkw3DK 1hPFfRc6KcOCPDjRa0yt0RHb5tNNE6hexqEAAKh3N0wg4mTKghUZFrSZOVIkvIbLPBny lrnw== X-Gm-Message-State: AOJu0Yxizky6pSLurJP7YbuzY48H8AjjI1SDWWGmIKOhL0csSALUfon/ j1yJDgHpdA8EYCr91mXkmfTKWDUkjgUfSA== X-Google-Smtp-Source: AGHT+IGXW6bDYha2dA0ASVMwJLUIRmhZZxlyPga7YQvawvXp0Yvzaa/Cyu+lDWzECFfNlABISXhQ2A== X-Received: by 2002:a17:902:d2cd:b0:1c1:d730:f0cf with SMTP id n13-20020a170902d2cd00b001c1d730f0cfmr2573063plc.20.1693111741007; Sat, 26 Aug 2023 21:49:01 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:bd86:4b0c:f073:c134]) by smtp.gmail.com with ESMTPSA id x2-20020a170902ea8200b001bb97e51ab4sm4553324plb.98.2023.08.26.21.49.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Aug 2023 21:49:00 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 3562E11423B7; Sun, 27 Aug 2023 14:18:58 +0930 (ACST) Date: Sun, 27 Aug 2023 14:18:58 +0930 From: Alan Modra To: binutils@sourceware.org Subject: comdat_hash memory leaks Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3033.7 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Entries added to the hash table with bfd_malloc ought to be freed when the hash table is deleted. This patch adds the necessary del_f to the htab_create call, and delays creating the table until an IMAGE_SCN_LNK_COMDAT symbol is read. * peicode.h (pe_mkobject): Move comdat_hash creation.. (htab_hash_flags, htab_eq_flags): ..and these support functions.. * coffcode.h (handle_COMDAT): ..to here, renaming support to (comdat_hashf, comdat_eqf): ..this and adding.. (comdat_delf): ..this new function. diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 2d40c5cfcac..03c1788a1c9 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -853,6 +853,29 @@ styp_to_sec_flags (bfd *abfd, #else /* COFF_WITH_PE */ +static hashval_t +comdat_hashf (const void *entry) +{ + const struct comdat_hash_entry *fe = entry; + return fe->target_index; +} + +static int +comdat_eqf (const void *e1, const void *e2) +{ + const struct comdat_hash_entry *fe1 = e1; + const struct comdat_hash_entry *fe2 = e2; + return fe1->target_index == fe2->target_index; +} + +static void +comdat_delf (void *ent) +{ + struct comdat_hash_entry *e = ent; + free (e->symname); + free (e); +} + static struct comdat_hash_entry * find_flags (htab_t comdat_hash, int target_index) { @@ -1085,6 +1108,14 @@ static bool handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name, asection *section) { + if (pe_data (abfd)->comdat_hash == NULL) + { + pe_data (abfd)->comdat_hash = htab_create (10, comdat_hashf, comdat_eqf, + comdat_delf); + if (pe_data (abfd)->comdat_hash == NULL) + return false; + } + if (htab_elements (pe_data (abfd)->comdat_hash) == 0) if (! fill_comdat_hash (abfd)) return false; diff --git a/bfd/peicode.h b/bfd/peicode.h index e1d06606575..1ff13b0313d 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -255,21 +255,6 @@ coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in) #endif } -static hashval_t -htab_hash_flags (const void *entry) -{ - const struct comdat_hash_entry *fe = entry; - return fe->target_index; -} - -static int -htab_eq_flags (const void *e1, const void *e2) -{ - const struct comdat_hash_entry *fe1 = e1; - const struct comdat_hash_entry *fe2 = e2; - return fe1->target_index == fe2->target_index; -} - static bool pe_mkobject (bfd * abfd) { @@ -306,8 +291,6 @@ pe_mkobject (bfd * abfd) pe->dos_message[14] = 0x24; pe->dos_message[15] = 0x0; - pe->comdat_hash = htab_create (10, htab_hash_flags, htab_eq_flags, NULL); - memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr); bfd_coff_long_section_names (abfd) -- Alan Modra Australia Development Lab, IBM