gpt4 book ai didi

c - 如何正确关闭和释放ALSA资源

转载 作者:行者123 更新时间:2023-11-30 17:22:34 25 4
gpt4 key购买 nike

如何正确关闭和释放 ALSA(和硬件参数)资源?我找到了很多例子。一切都不同。都有memleak。

例如:

#include <stdio.h>
#include <unistd.h>
#include <alsa/asoundlib.h>

int
main()
{
snd_pcm_t *dev;

snd_pcm_open(&dev, "default", SND_PCM_STREAM_PLAYBACK, 0);
snd_pcm_close(dev);

return 0;
}

Valgrind 报告:

==19586== LEAK SUMMARY:
==19586== definitely lost: 0 bytes in 0 blocks
==19586== indirectly lost: 0 bytes in 0 blocks
==19586== possibly lost: 65,525 bytes in 2,020 blocks
==19586== still reachable: 298 bytes in 6 blocks
==19586== suppressed: 0 bytes in 0 blocks
==19586== Reachable blocks (those to which a pointer was found) are not shown.
==19586== To see them, rerun with: --leak-check=full --show-reachable=yes
==19586==
==19586== ERROR SUMMARY: 116 errors from 116 contexts (suppressed: 4 from 4)
--19586--
--19586-- used_suppression: 2 dl-hack3-cond-1
--19586-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
==19586==
==19586== ERROR SUMMARY: 116 errors from 116 contexts (suppressed: 4 from 4)

更新:

如果没有 snd_pcm_close(),我们会从 117 个上下文中得到 117 个错误 )))

最佳答案

如果在 snd_pcm_close(handle); 之后调用 snd_config_update_free_global() 释放全局配置,则不会出现泄漏

关于c - 如何正确关闭和释放ALSA资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27998009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com