[noup] zephyr: fix socket and memory leak when remove interface#148
[noup] zephyr: fix socket and memory leak when remove interface#148GaofengZhangNXP wants to merge 3 commits into
Conversation
2fef0bf to
0d898c8
Compare
4b0d5ca to
38d199b
Compare
|
should not mention |
63a323a to
cc9e4de
Compare
There was a problem hiding this comment.
Pull request overview
This PR targets Zephyr-specific cleanup issues during Wi-Fi reset/interface removal by improving teardown paths in the Zephyr driver and hostapd control interface so resources (control sockets/fds and allocated context) don’t leak.
Changes:
- Update Zephyr hostapd driver deinit to retrieve
dev_opsviaget_dev_ops(if_ctx->dev_ctx)and add NULL safety. - Add
zephyr_hostapd_ctrl_deinit()API and implement deferred fd cleanup in the eloop thread. - Simplify hostapd CLI connection close logic (removing unnecessary detach for a connection that was never attached).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/drivers/driver_zephyr.c | Adjusts hostapd deinit to fetch dev_ops from the device context and avoid NULL dereference. |
| hostapd/hostapd_cli_zephyr.h | Exposes the new Zephyr hostapd control deinit function. |
| hostapd/hostapd_cli_zephyr.c | Implements control deinit and fd cleanup logic to prevent control fd leaks on interface removal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
35ddc60 to
5064f5c
Compare
|
You can run |
5064f5c to
89b6551
Compare
update it |
22f6700 to
883db12
Compare
I executed git clang-format HEAD~1, but it reformatted the code to use spaces for indentation at the beginning of each line instead of tabs. According to the Zephyr coding style, tabs should be used for indentation. My original changes were all indented with tabs, so the formatting applied by git clang-format appears to be inconsistent with the expected Zephyr style. |
I cannot recommend to use clang-format for anything, it usually does bad job as you have noticed. |
:). Probably because this repo doesn't have |
thank your suggestion, I can use the .clang-format to format hostapd repo and zephyr repo PR, and update it |
|
|
||
| dev_ops->hapd_deinit(if_ctx->dev_priv); | ||
|
|
||
| out: |
There was a problem hiding this comment.
This warrants a separate commit as its fixing a different leak.
There was a problem hiding this comment.
you are right, this fix is a separate commit, you can check it
There was a problem hiding this comment.
This is still part of the original commit to fix the control socket leak.
update it |
0822b1b to
52e3e11
Compare
jukkar
left a comment
There was a problem hiding this comment.
Please adjust the commit messages a bit to make it clear that this is a zephyr specific change, so
[noup] zephyr: ....
8ada1d6 to
883effa
Compare
a281f73 to
9981f90
Compare
When the interface is removed, the hostapd control socket is not closed, resulting in a hostapd control socket leak. Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
hostapd_deinit can't get zephyr driver dev_ops, and can't free hostapd memory when hostapd_init Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
9981f90 to
f8abf18
Compare
update it |
when hostapd and supplicant interface is removed, zep_drv_if_ctx is free in hostapd and supplicant driver deinit. so need to check zep_drv_if_ctx if function parameteris zep_drv_if_ctx Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
f8abf18 to
1d52ab3
Compare
| if_ctx = priv; | ||
|
|
||
| dev_ops = (struct zep_wpa_supp_dev_ops *)if_ctx->dev_ops; | ||
| if (!dev_ops->hapd_deinit) { | ||
| dev_ops = get_dev_ops(if_ctx->dev_ctx); | ||
| if (!dev_ops || !dev_ops->hapd_deinit) { |
| /* Close ctrl_conn (just frees wpa_ctrl struct, no fd close) */ | ||
| hostapd_cli_close_connection(hapd); | ||
| ctx = os_zalloc(sizeof(*ctx)); | ||
| if (!ctx) { | ||
| /* Best-effort cleanup even on OOM to avoid leaking fds/socks */ | ||
| if (hapd->recv_sock >= 0) { | ||
| eloop_unregister_read_sock(hapd->recv_sock); | ||
| close(hapd->recv_sock); | ||
| hapd->recv_sock = -1; | ||
| } | ||
| if (hapd->send_sock >= 0) { | ||
| close(hapd->send_sock); | ||
| hapd->send_sock = -1; | ||
| } | ||
| return; | ||
| } | ||
| ctx->recv_sock = hapd->recv_sock; | ||
| ctx->send_sock = hapd->send_sock; | ||
| hapd->recv_sock = -1; | ||
| hapd->send_sock = -1; | ||
| /* timeout=0: execute in next eloop iteration, in eloop thread */ | ||
| if (eloop_register_timeout(0, 0, hapd_ctrl_close_fds, ctx, NULL) < 0) | ||
| hapd_ctrl_close_fds(ctx, NULL); |
| int zephyr_hostapd_ctrl_init(void *ctx); | ||
| void zephyr_hostapd_ctrl_deinit(void *hapd); | ||
| int zephyr_hostapd_ctrl_zephyr_cmd(struct wpa_ctrl *ctrl, int argc, const char *argv[]); |
resulting in a hostapd control socket leak.
and can't free hostapd memory during hostapd_init