Skip to content

Commit

Permalink
Fix insufficient memory allocation in ESP32 select_thread_loop
Browse files Browse the repository at this point in the history
Building with ESP-IDF v5.4 emmits the folowing warning:
```
/__w/AtomVM/AtomVM/src/platforms/esp32/components/avm_sys/sys.c: In function 'select_thread_loop':
/__w/AtomVM/AtomVM/src/platforms/esp32/components/avm_sys/sys.c:680:26: warning: allocation of
 insufficient size '0' for type 'struct pollfd' with size '8' [-Walloc-size]
  680 |     struct pollfd *fds = malloc(0);
      |                          ^~~~~~
```

These changes fix the problem by allocating enough memory to hold the struct.

Signed-off-by: Winford <winford@object.stream>
  • Loading branch information
UncleGrumpy committed Jan 5, 2025
1 parent dfc3bf1 commit 5632eb5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ certain VM instructions are used.
- Fixed an issue where a timeout would occur immediately in a race condition
- Fixed SPI close command
- Added missing lock on socket structure
- Fixed insufficient memory allocation in ESP32 select_thread_loop

## [0.6.5] - 2024-10-15

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/components/avm_sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ static void *select_thread_loop(void *arg)
{
GlobalContext *glb = arg;
struct ESP32PlatformData *platform = glb->platform_data;
struct pollfd *fds = malloc(0);
struct pollfd *fds = malloc(sizeof(struct pollfd));
while (!platform->select_thread_exit) {
int select_events_poll_count = platform->select_events_poll_count;
int poll_count = 1;
Expand Down

0 comments on commit 5632eb5

Please sign in to comment.