Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	"Alexander V . Tikhonov" <avtikhon@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org,
	Alexander Turenko <alexander.turenko@tarantool.org>
Subject: [Tarantool-patches] [PATCH 1/2] popen: fix access to freed memory after :close()
Date: Mon, 18 May 2020 14:42:57 +0300	[thread overview]
Message-ID: <20510af779a64e57b1f31ccc9245f9a0e9710cf2.1589799677.git.alexander.turenko@tarantool.org> (raw)
In-Reply-To: <cover.1589799677.git.alexander.turenko@tarantool.org>

popen_delete() always frees a handle memory even when it reports a
failure to send SIGKILL, see [1]. We should reflect this contract in
popen_handle:close() and mark the handle as closed despite
popen_delete() return value.

There are cases, when killpg() fails with EPERM on Mac OS, so
popen_delete() reports a failure. See [1] for more information.

[1]: 01657bfbb9b34997f20d27405226a9affdeeb520 ('popen: always free
resources in popen_delete()')

Fixes #4995
---
 src/lua/popen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lua/popen.c b/src/lua/popen.c
index 0e930e91b..471964ee6 100644
--- a/src/lua/popen.c
+++ b/src/lua/popen.c
@@ -2258,11 +2258,11 @@ lbox_popen_close(struct lua_State *L)
 		return 1;
 	}
 
+	luaT_mark_popen_handle_closed(L, 1);
+
 	if (popen_delete(handle) != 0)
 		return luaT_push_nil_and_error(L);
 
-	luaT_mark_popen_handle_closed(L, 1);
-
 	lua_pushboolean(L, true);
 	return 1;
 }
-- 
2.25.0

  reply	other threads:[~2020-05-18 11:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 11:42 [Tarantool-patches] [PATCH 0/2] popen fixes Alexander Turenko
2020-05-18 11:42 ` Alexander Turenko [this message]
2020-05-18 11:42 ` [Tarantool-patches] [PATCH 2/2] test: popen: fix popen test 'hang' under test-run Alexander Turenko
2020-05-18 21:57 ` [Tarantool-patches] [PATCH 0/2] popen fixes Vladislav Shpilevoy
2020-05-19  5:00 ` Alexander V. Tikhonov
2020-05-20  6:35 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20510af779a64e57b1f31ccc9245f9a0e9710cf2.1589799677.git.alexander.turenko@tarantool.org \
    --to=alexander.turenko@tarantool.org \
    --cc=avtikhon@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/2] popen: fix access to freed memory after :close()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox