Fixed ticket #376: Bug in ioqueue prevents re-registering more than PJ_IOQUEUE_MAX_HANDLES (thanks Phil Torre)
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1440 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c
index 48612d2..1fb3660 100644
--- a/pjlib/src/pj/ioqueue_select.c
+++ b/pjlib/src/pj/ioqueue_select.c
@@ -119,6 +119,11 @@
*/
#include "ioqueue_common_abs.c"
+#if PJ_IOQUEUE_HAS_SAFE_UNREG
+/* Scan closing keys to be put to free list again */
+static void scan_closing_keys(pj_ioqueue_t *ioqueue);
+#endif
+
/*
* pj_ioqueue_name()
*/
@@ -321,6 +326,10 @@
* the key from the free list. Otherwise allocate a new one.
*/
#if PJ_IOQUEUE_HAS_SAFE_UNREG
+
+ /* Scan closing_keys first to let them come back to free_list */
+ scan_closing_keys(ioqueue);
+
pj_assert(!pj_list_empty(&ioqueue->free_list));
if (pj_list_empty(&ioqueue->free_list)) {
rc = PJ_ETOOMANY;