@@ -92,7 +92,9 @@ esp_err_t esp_linenoise_set_event_fd(esp_linenoise_instance_t *instance)
9292
9393 /* Tell linenoise what file descriptor to add to the read file descriptor set,
9494 * that will be used to signal a read termination */
95- esp_vfs_eventfd_config_t eventfd_config = ESP_VFS_EVENTD_CONFIG_DEFAULT ();
95+ esp_vfs_eventfd_config_t eventfd_config = {
96+ .max_fds = ESP_LINENOISE_MAX_INSTANCE_NB
97+ };
9698 esp_err_t ret = esp_vfs_eventfd_register (& eventfd_config );
9799 int new_eventfd = -1 ;
98100 if (ret != ESP_ERR_INVALID_ARG ) {
@@ -102,6 +104,12 @@ esp_err_t esp_linenoise_set_event_fd(esp_linenoise_instance_t *instance)
102104 return ESP_FAIL ;
103105 }
104106
107+ /* make sure the FD returned is not -1, which would indicate that eventfd
108+ * has reached the maximum number of FDs it can create */
109+ if (new_eventfd == -1 ) {
110+ return ESP_FAIL ;
111+ }
112+
105113 state -> mux = xSemaphoreCreateMutex ();
106114 if (state -> mux == NULL ) {
107115 close (new_eventfd );
@@ -136,6 +144,9 @@ esp_err_t esp_linenoise_remove_event_fd(esp_linenoise_instance_t *instance)
136144 eventfd_pair_t * prev = NULL ;
137145 SLIST_FOREACH (cur , & s_eventfd_pairs , next_pair ) {
138146 if (cur -> in_fd == config -> in_fd ) {
147+ /* close the eventfd */
148+ close (cur -> eventfd );
149+
139150 if (prev == NULL ) {
140151 /* remove head */
141152 SLIST_REMOVE_HEAD (& s_eventfd_pairs , next_pair );
0 commit comments