From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 91CBA6E238; Wed, 2 Dec 2026 11:35:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 91CBA6E238 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1796200534; bh=zMsvw2KxqgEj+blRJRz/XZhuegytuXjXQTvwYKFkcRU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ynfDi/oLkssmDPgUN6LqipG0vGbX5aqZkb1mBwoKwg2Je13EwwHKPJBQ9lCr30KeS 354aXtWyDGoBUiayzP+Wb4vOmV7nPkyIrYGutb3MvnDKpDEwTf0mx1xkscPe0O5txE tOUtm/eOUONfOn7gBdXKywHJBgCWvqARYr1s0yrU= Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B60266E238 for ; Wed, 2 Dec 2026 11:35:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B60266E238 Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5c31cdbeec9so5917142e87.2 for ; Wed, 02 Dec 2026 00:35:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796200500; x=1796805300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=K69j/b2coPOejo8Vzj1YzWKqW7ygq/iU8M0Fe5XxXRA=; b=SjLJA2++IlbRq6g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Sx2xeQGpufRV2CUCiR0NJL0HpJa1LtS X-Received: by 2002:a05:6512:6881:20b0:5bf:b144:fcbb with SMTP id 2adb3069b0e04-5c1bc7d1ffemr7209710e87.28.1796200499666; Wed, 02 Dec 2026 00:34:59 -0800 (PST) Received: from localhost ([81.9.21.190]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd0171c7sm9405745e87.31.2026.12.02.00.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 00:34:59 -0800 (PST) To: tarantool-patches@dev.tarantool.org, Sergey Kaplun , e.temirgaleev@tarantool.org Date: Wed, 2 Dec 2026 11:34:52 +0300 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 luajit 3/3] sysprof: release resources on a halted profiler X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Sergey Bronnikov If the stream fails (e.g., because of ENOSPC), the profiler moves to the SPS_HALT state. `lj_sysprof_stop()` returns PROFILE_ERRIO but does not call the `on_stop` callback, so the profile context and the output file descriptor are leaked. Call `on_stop` when the halted profiler is stopped, as it is already done when starting fails or when the stream is stopped in a regular way. Preserve the saved errno because `on_stop` may change it. Follows up tarantool/tarantool#11620 --- src/lj_sysprof.c | 4 +++- test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lj_sysprof.c b/src/lj_sysprof.c index 99bcc088..667c93a8 100644 --- a/src/lj_sysprof.c +++ b/src/lj_sysprof.c @@ -509,9 +509,11 @@ int lj_sysprof_stop(lua_State *L) lj_profile_timer_stop(&sp->timer); if (SPS_HALT == sp->state) { - errno = sp->saved_errno; + const int saved_errno = sp->saved_errno; sp->state = SPS_IDLE; /* wbuf was terminated when error occurred. */ + sp->on_stop(sp->opt.ctx, sp->out.buf); + errno = saved_errno; return PROFILE_ERRIO; } diff --git a/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c b/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c index df93fd7e..ee404eda 100644 --- a/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c +++ b/test/tarantool-c-tests/gh-11620-sysprof-enospc-crash.test.c @@ -125,6 +125,8 @@ static int sysprof_enospc_during_sampling(void *test_state) errno = 0; assert_int_equal(luaM_sysprof_stop(L), PROFILE_ERRIO); assert_int_equal(errno, ENOSPC); + /* The error path releases the profiler resources. */ + assert_int_equal(ctx.on_stop_calls, 1); /* Counters are still available. */ assert_true(luaM_sysprof_report(&counters) == PROFILE_SUCCESS); -- 2.56.0