Skip to content

Commit 627129c

Browse files
committed
fix(esp_linenoise): close eventfd associated with an instance when deleting it
1 parent 9773e44 commit 627129c

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

esp_linenoise/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
menu "esp_linenoise configuration"
2+
config ESP_LINENOISE_MAX_INSTANCE_NB
3+
int "Maximum number of esp_linenoise instances that can be created simultaneously"
4+
range 1 32
5+
default 5
6+
help
7+
Maximum number of esp_linenoise instances that can simultaneously be created.
8+
This limitation in the number of esp_linenoise is only present when esp_linenoise_abort is used.
9+
endmenu

esp_linenoise/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.0.1"
1+
version: "1.0.2"
22
description: "ESP Linenoise - Line editing C library"
33
url: https://github.com/espressif/idf-extra-components/tree/master/esp_linenoise
44
license: Apache-2.0

esp_linenoise/src/esp_linenoise_internals.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)