[Asterisk-code-review] res timing: Don't close FD 0 when out of open files. (asterisk[master])

Walter Doekes asteriskteam at digium.com
Thu Jul 2 05:13:37 CDT 2015


Walter Doekes has uploaded a new change for review.

  https://gerrit.asterisk.org/761

Change subject: res_timing: Don't close FD 0 when out of open files.
......................................................................

res_timing: Don't close FD 0 when out of open files.

This fixes so a failure to get a timer file descriptor does not cascade
to closing FD 0.

On error, both res_timing_kqueue and res_timing_timerfd would call the
destructor before setting the file handle. The file handle had been
initialized to 0, causing FD 0 to be closed. This in turn, resulted in
floods of "CLI>" messages and an unusable terminal.

ASTERISK-19277 #close
Reported by: Barry Chern

For the master branch, this was already fixed. This patch only ensures
that we do not attempt to close a negative file descriptor.

Change-Id: I147d7e33726c6e5a2751928d56561494f5800350
---
M res/res_timing_kqueue.c
M res/res_timing_timerfd.c
2 files changed, 6 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/761/1

diff --git a/res/res_timing_kqueue.c b/res/res_timing_kqueue.c
index dd2a839..f568144 100644
--- a/res/res_timing_kqueue.c
+++ b/res/res_timing_kqueue.c
@@ -159,7 +159,9 @@
 	struct kqueue_timer *timer = obj;
 	ast_debug(5, "[%d]: Timer Destroy\n", timer->handle);
 	kqueue_timer_fini_continuous_event(timer);
-	close(timer->handle);
+	if (timer->handle > -1) {
+		close(timer->handle);
+	}
 }
 
 static void *kqueue_timer_open(void)
diff --git a/res/res_timing_timerfd.c b/res/res_timing_timerfd.c
index 5ee21fc..71f74bb 100644
--- a/res/res_timing_timerfd.c
+++ b/res/res_timing_timerfd.c
@@ -76,8 +76,9 @@
 static void timer_destroy(void *obj)
 {
 	struct timerfd_timer *timer = obj;
-
-	close(timer->fd);
+	if (timer->fd > -1) {
+		close(timer->fd);
+	}
 }
 
 static void *timerfd_timer_open(void)

-- 
To view, visit https://gerrit.asterisk.org/761
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I147d7e33726c6e5a2751928d56561494f5800350
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Walter Doekes <walter+asterisk at wjd.nu>



More information about the asterisk-code-review mailing list