From patchwork Tue Jun 4 09:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1943229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=tC3JxUfi; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Pp5mxbna; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=tC3JxUfi; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Pp5mxbna; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vtm0p2FfYz20Tb for ; Tue, 4 Jun 2024 19:45:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6591C3A46491 for ; Tue, 4 Jun 2024 09:45:12 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 7B9D2392A7F5 for ; Tue, 4 Jun 2024 09:44:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B9D2392A7F5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7B9D2392A7F5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717494298; cv=none; b=cP3KLjrPw37qPI0UKGH0qaoVHWRh/C2Ws0YevBiIrM6gdS7h4UyPuHB1auqbfAKp5VU5jkT93FhDUA1oevyx5kCG2LbnedGv/AuP/esivK2pag6pOCNoZJximZ5X1ztkxobGlAsSB8Viy3LtKLFPDajfbDqw81FHLOMJU6hgt7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717494298; c=relaxed/simple; bh=IIKyTfI9MxDnRN6Z6B2c1v2pfF9cSo2n/E34sMTBuPw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=QPwZIRHQnyrKgMJTpSqUcgPVzQ45yplqUQJ5dRG4qE9iWYK+1o8Gdd/F4HtM+IvgdDoghaEPUDpgrteTF6ghh0MAuJJm72IngPB39VCovPu5YgRVKVS6OVBPa84d9GOjEz2o2PHtH+VUayUw1oQELOS6BwaEhphAEq14OsVLZNY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from hawking.nue2.suse.org (unknown [IPv6:2a07:de40:a101:3:10:168:4:11]) by smtp-out2.suse.de (Postfix) with ESMTP id 22BF01F7E1 for ; Tue, 4 Jun 2024 09:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717494295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=nqCQDam8snBewjoS6ZIMAy4+wVyLHsTh3bE65e3ieSQ=; b=tC3JxUfiGlEUXEAWxMZzcnaZ3qlIT7/dTOrjnB3OJ9BCwm1ZKm/wjCdTh+DSrqzFFVzIat mX0KXCE5dGf/gSQqUJeCaEMLTHEyCigf/iGJmRvMa4YG1BsZ/3nK278BZqe2srwjfH4Pvd LyZCYsoWVyzC3NnVE+kJMasF1Dsc3J4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717494295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=nqCQDam8snBewjoS6ZIMAy4+wVyLHsTh3bE65e3ieSQ=; b=Pp5mxbnarXlvOFJguFGbEjKTpGfI/TyLx2u56/dU5DcU1RpYzK9H47kvzZR3WRwGmqxF+d yZElKFNxl3jzwVAw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=tC3JxUfi; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Pp5mxbna DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717494295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=nqCQDam8snBewjoS6ZIMAy4+wVyLHsTh3bE65e3ieSQ=; b=tC3JxUfiGlEUXEAWxMZzcnaZ3qlIT7/dTOrjnB3OJ9BCwm1ZKm/wjCdTh+DSrqzFFVzIat mX0KXCE5dGf/gSQqUJeCaEMLTHEyCigf/iGJmRvMa4YG1BsZ/3nK278BZqe2srwjfH4Pvd LyZCYsoWVyzC3NnVE+kJMasF1Dsc3J4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717494295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=nqCQDam8snBewjoS6ZIMAy4+wVyLHsTh3bE65e3ieSQ=; b=Pp5mxbnarXlvOFJguFGbEjKTpGfI/TyLx2u56/dU5DcU1RpYzK9H47kvzZR3WRwGmqxF+d yZElKFNxl3jzwVAw== Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id C18E84A0552; Tue, 4 Jun 2024 11:44:54 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Remove memory leak in fdopen (bug 31840) X-Yow: RELAX!! ... This is gonna be a HEALING EXPERIENCE!! Besides, I work for DING DONGS! Date: Tue, 04 Jun 2024 11:44:54 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-0.33 / 50.00]; BAYES_HAM(-2.97)[99.88%]; HFILTER_HOSTNAME_UNKNOWN(2.50)[]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; ONCE_RECEIVED(1.20)[]; RDNS_NONE(1.00)[]; HFILTER_HELO_IP_A(1.00)[hawking.nue2.suse.org]; NEURAL_HAM_LONG(-1.00)[-0.999]; HFILTER_HELO_NORES_A_OR_MX(0.30)[hawking.nue2.suse.org]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.15)[-0.746]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MX_GOOD(-0.01)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; DIRECT_TO_MX(0.00)[Gnus/5.13 (Gnus v5.13)]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email] X-Spam-Score: -0.33 X-Spamd-Bar: / X-Rspamd-Queue-Id: 22BF01F7E1 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Deallocate the memory for the FILE structure when seeking to the end fails in append mode. Fixes: ea33158c96 ("Fix offset caching for streams and use it for ftell (BZ #16680)") Reviewed-by: Florian Weimer --- libio/iofdopen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libio/iofdopen.c b/libio/iofdopen.c index 2583fb8255..14fbc7b257 100644 --- a/libio/iofdopen.c +++ b/libio/iofdopen.c @@ -156,7 +156,11 @@ _IO_new_fdopen (int fd, const char *mode) { off64_t new_pos = _IO_SYSSEEK (&new_f->fp.file, 0, _IO_seek_end); if (new_pos == _IO_pos_BAD && errno != ESPIPE) - return NULL; + { + _IO_un_link (&new_f->fp); + free (new_f); + return NULL; + } } return &new_f->fp.file; }