fix: audio_free_buffers() add a NULL check.#441
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom Dec 26, 2025
Merged
fix: audio_free_buffers() add a NULL check.#441deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
Conversation
On the Zhaoxin processor, there is a probabilistic occurrence of null pointer/double-free issues with `audio_buffers[i].data`, so a NULL check needs to be added. 在兆芯处理器上,audio_buffers[i].data 概率性出现空指针/重复释放的情况,所以需要增加 NULL 判断。 Bug: https://pms.uniontech.com/bug-view-345713.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds defensive null checking and pointer reset to the audio buffer cleanup routine to prevent null pointer and double-free issues observed on Zhaoxin processors. Flow diagram for updated audio_free_buffers logicflowchart TD
A[start_audio_free_buffers] --> B[check_audio_buffers_not_null]
B --> C[initialize_i_to_0]
C --> D{is_i_less_than_AUDBUFF_NUM}
D -->|no| H[free_audio_buffers_and_return]
D -->|yes| E[check_audio_buffers_i_data_is_null]
E -->|yes| F[increment_i]
E -->|no| G[free_audio_buffers_i_data_and_set_to_null]
G --> F
F --> D
subgraph loop_over_audio_buffers
C
D
E
F
G
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来对这段代码进行审查分析:
总体来说,这个修改是合理且必要的,有效提高了代码的安全性和稳定性。建议按照上述补充建议进一步完善代码。 |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Instead of just guarding against NULL/double-free here, consider tracing and fixing the underlying lifecycle issue that leaves
audio_buffers[i].datain an inconsistent state, otherwise the bug may reappear in other call sites. - If the project convention is to keep comments in a single language, you may want to either translate the new comment to English or mirror it with an English version for consistency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of just guarding against NULL/double-free here, consider tracing and fixing the underlying lifecycle issue that leaves `audio_buffers[i].data` in an inconsistent state, otherwise the bug may reappear in other call sites.
- If the project convention is to keep comments in a single language, you may want to either translate the new comment to English or mirror it with an English version for consistency.
## Individual Comments
### Comment 1
<location> `libcam/libcam_audio/audio.c:134-135` </location>
<code_context>
for(i = 0; i < AUDBUFF_NUM; ++i)
{
+ // 在兆芯处理器上,audio_buffers[i].data 概率性出现空指针/重复释放的情况,所以这里需要增加判断
+ if (audio_buffers[i].data == NULL) {
+ continue;
+ }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Silently skipping NULL entries may hide the underlying lifecycle issue.
If `audio_buffers[i].data` is unexpectedly NULL, we now just continue, which may hide a real lifecycle bug on that platform. Please at least log or count these occurrences so you can tell the difference between "never allocated" and "became NULL due to a bug" and make future debugging feasible.
Suggested implementation:
```c
for(i = 0; i < AUDBUFF_NUM; ++i)
{
// 在兆芯处理器上,audio_buffers[i].data 概率性出现空指针/重复释放的情况,所以这里需要增加判断
if (audio_buffers[i].data == NULL) {
// 避免静默跳过 NULL 指针,记录一次以便后续排查生命周期问题
fprintf(stderr,
"libcam_audio: audio_buffers[%d].data is NULL while releasing buffers\n",
i);
continue;
}
free(audio_buffers[i].data);
audio_buffers[i].data = NULL;
}
free(audio_buffers);
```
1. At the top of `libcam/libcam_audio/audio.c`, ensure `#include <stdio.h>` is present so that `fprintf` is available.
2. If the project uses its own logging abstraction (e.g. `LOGE`, `CAM_ERR`, etc.), replace `fprintf(stderr, ...)` with the appropriate logging macro to be consistent with the rest of the codebase.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
max-lvs
approved these changes
Dec 26, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichaofan2008, max-lvs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
4c8d011
into
linuxdeepin:release/eagle
16 of 18 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the Zhaoxin processor, there is a probabilistic occurrence of null pointer/double-free issues with
audio_buffers[i].data, so a NULL check needs to be added.在兆芯处理器上,audio_buffers[i].data 概率性出现空指针/重复释放的情况,所以需要增加 NULL 判断。
Bug: https://pms.uniontech.com/bug-view-345713.html
Summary by Sourcery
Bug Fixes: