2015-01-17 12 views
0

ALSA (및 hw 매개 변수) 리소스를 올바르게 닫고 무료로 저장하는 방법은 무엇입니까? 많은 예를 발견했습니다. 모두 다르다. 모두 memleak 있습니다.ALSA 리소스를 올바르게 닫고 해제하는 방법

#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) 

UPD : 당신은 원 snd_pcm_close없이

() 우리는 117 컨텍스트에서 117 오류가)))

+0

[alsa-mem leak?] (http://stackoverflow.com/questions/13478861/alsa-mem-leak) –

+0

@CL의 가능한 복제본. 어디에서 토론을 계속합니까? 이리? 아직도 memleak (2 문맥에서 2 오류)가 있기 때문에 – Deep

+0

그 문맥은 무엇입니까? –

답변

0

snd_config_update_free_global() AF를 호출하여 글로벌 구성을 해제하면 누수가 발생하지 않습니다. TER snd_pcm_close (핸들);

+0

감사. 하지만 이것은 데비안 6의 alsa 버그입니다. 실제는 아닙니다 - 오래된 오래된 stable은 사라졌습니다 :) – Deep

0

가 alsalib 1.1.4.1로이 예제를 테스트 :

4,320 bytes in 60 blocks are possibly lost in loss record 91 of 94 

을하고 요약은 다음과 같습니다

#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); 
    snd_config_update_free_global(); 

    return 0; 
} 

추가 snd_config_update_free_global을() 파올로에 의해 제안, Valgrind의이 같은 경고를 많이 표시하고 아마도 손실 된 블록 표시 :

==499== LEAK SUMMARY: 
==499== definitely lost: 0 bytes in 0 blocks 
==499== indirectly lost: 0 bytes in 0 blocks 
==499==  possibly lost: 43,011 bytes in 1,311 blocks 
==499== still reachable: 111,131 bytes in 128 blocks 
==499==   suppressed: 0 bytes in 0 blocks 
==499== Reachable blocks (those to which a pointer was found) are not shown. 
==499== To see them, rerun with: --leak-check=full --show-leak-kinds=all 

그걸로 무엇을 할 수 있습니까?