From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp-29.smtpout.orange.fr [80.12.242.29]) by sourceware.org (Postfix) with ESMTPS id 19D2C3858C1F for ; Tue, 12 Sep 2023 12:05:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19D2C3858C1F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=jacob.remcomp.fr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=jacob.remcomp.fr Received: from smtpclient.apple ([90.22.252.13]) by smtp.orange.fr with ESMTPS id g29DqpTuCmTYjg29DqaaD5; Tue, 12 Sep 2023 14:05:39 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1694520339; bh=SfC+f+ay+ZxrC0Uv3D3sB5fkeEy0RgzmzF0rX0LrGGw=; h=From:Subject:Date:To; b=o4t8mdjHGNpk/rrMpe4r3Ao+H4yN7MEl+CsGRcfkH7mu4OKKke8krfn9qsSlLzpJc jiu1XAlcrP5uzZIhZ5fUEPDt0TF+TklEZd0+6CB6bks/bDf9kYAVdgJ/NOSBkVcbvd kcTfolC2zSUGkDyw3SUBVjF5Dx9wIa+fq9ywNFK/AdV2mLVa33cIBf03uWhccRIgNA U6vcGBPPojfKBnRHMdfbuUrTGPkKzRvBTfsKlIhmI6ClQKdJrjPu9LsCdUNBjjl2K+ NF+mSPe+0bETqWDYaNl09EA/8/wElLfmQjZJOBT5RIfhqEreaOF1+UzuL3Cnp0POp7 8+MVcS9wMZCcQ== X-ME-Helo: smtpclient.apple X-ME-Date: Tue, 12 Sep 2023 14:05:39 +0200 X-ME-IP: 90.22.252.13 From: jacob navia Content-Type: multipart/alternative; boundary="Apple-Mail=_5BD334EE-8219-4091-A4B2-F5EB1ABDE8F0" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Possible Memory leak in bed hash.c Message-Id: <86B413C7-E812-411A-A790-90B80E81B411@jacob.remcomp.fr> Date: Tue, 12 Sep 2023 14:05:29 +0200 To: binutils@sourceware.org X-Mailer: Apple Mail (2.3731.700.6) X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --Apple-Mail=_5BD334EE-8219-4091-A4B2-F5EB1ABDE8F0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Function: bfd_elf_strtab_init, file hash.c lines 94-126 Type of bug: Memory leak ------------------- Description: ------------- /* Create a new hash table. */ struct elf_strtab_hash *_bfd_elf_strtab_init(void) { struct elf_strtab_hash *table; size_t amt =3D sizeof(struct elf_strtab_hash); table =3D (struct elf_strtab_hash *)malloc(amt); if (table =3D=3D NULL)=20 return NULL;=20 // This call allocates several fields in the table. if (!bfd_hash_table_init(&table->table,elf_strtab_hash_newfunc, sizeof(struct elf_strtab_hash_entry))) { free(table); return NULL;=20 } table->sec_size =3D 0; table->size =3D 1; table->alloced =3D 64;=20 amt =3D sizeof(struct elf_strtab_hasn_entry *); table->array =3D ((struct elf_strtab_hash_entry **) malloc(table->alloced * amt)); if (table->array =3D=3D NULL) { free(table); <<<<<<<<<<<<<<<< MEMORY LEAK=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 return NULL;=20 } table->array[0] =3D NULL;=20 return table; } We call =C2=AB bfd_hash_table_init" that initializes the table with several= huge structures. It returns OK, and we go on with table->sec_size =3D 0; e= tc. Then, we attempt to allocate the array. If it fails, we free just the table, leaking all previously allocated subfi= elds. HOW TO FIX: =E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94 Just call =C2=AB bfd_hash_table_free =C2=BB instead of =C2=AB free =C2=BB=20 Priority: LOW In these times of plenty (gigabytes of RAM, etc) nobody cares about writing= good software.=20= --Apple-Mail=_5BD334EE-8219-4091-A4B2-F5EB1ABDE8F0--