mirror of https://github.com/jetkvm/kvm.git
Add NULL checks before snd_pcm_close() calls
Defensive programming to prevent undefined behavior when closing ALSA PCM handles. While the previous commit disabled assertions with -DNDEBUG, adding explicit NULL checks ensures graceful handling even if handles are unexpectedly NULL. All error paths that call snd_pcm_close() now verify the handle is non-NULL before closing, preventing potential crashes in edge cases.
This commit is contained in:
parent
fb6dbe53eb
commit
5ed70083ec
|
|
@ -605,7 +605,9 @@ int jetkvm_audio_capture_init() {
|
|||
if (err < 0) {
|
||||
snd_pcm_t *handle = pcm_capture_handle;
|
||||
pcm_capture_handle = NULL;
|
||||
snd_pcm_close(handle);
|
||||
if (handle) {
|
||||
snd_pcm_close(handle);
|
||||
}
|
||||
atomic_store(&capture_stop_requested, 0);
|
||||
capture_initializing = 0;
|
||||
return -2;
|
||||
|
|
@ -620,7 +622,9 @@ int jetkvm_audio_capture_init() {
|
|||
fflush(stderr);
|
||||
snd_pcm_t *handle = pcm_capture_handle;
|
||||
pcm_capture_handle = NULL;
|
||||
snd_pcm_close(handle);
|
||||
if (handle) {
|
||||
snd_pcm_close(handle);
|
||||
}
|
||||
atomic_store(&capture_stop_requested, 0);
|
||||
capture_initializing = 0;
|
||||
return -4;
|
||||
|
|
@ -644,7 +648,9 @@ int jetkvm_audio_capture_init() {
|
|||
fflush(stderr);
|
||||
snd_pcm_t *handle = pcm_capture_handle;
|
||||
pcm_capture_handle = NULL;
|
||||
snd_pcm_close(handle);
|
||||
if (handle) {
|
||||
snd_pcm_close(handle);
|
||||
}
|
||||
atomic_store(&capture_stop_requested, 0);
|
||||
capture_initializing = 0;
|
||||
return -3;
|
||||
|
|
@ -671,7 +677,9 @@ int jetkvm_audio_capture_init() {
|
|||
if (pcm_capture_handle) {
|
||||
snd_pcm_t *handle = pcm_capture_handle;
|
||||
pcm_capture_handle = NULL;
|
||||
snd_pcm_close(handle);
|
||||
if (handle) {
|
||||
snd_pcm_close(handle);
|
||||
}
|
||||
}
|
||||
atomic_store(&capture_stop_requested, 0);
|
||||
capture_initializing = 0;
|
||||
|
|
@ -888,7 +896,9 @@ int jetkvm_audio_playback_init() {
|
|||
if (err < 0) {
|
||||
snd_pcm_t *handle = pcm_playback_handle;
|
||||
pcm_playback_handle = NULL;
|
||||
snd_pcm_close(handle);
|
||||
if (handle) {
|
||||
snd_pcm_close(handle);
|
||||
}
|
||||
atomic_store(&playback_stop_requested, 0);
|
||||
playback_initializing = 0;
|
||||
return -1;
|
||||
|
|
@ -903,7 +913,9 @@ int jetkvm_audio_playback_init() {
|
|||
if (!decoder || opus_err != OPUS_OK) {
|
||||
snd_pcm_t *handle = pcm_playback_handle;
|
||||
pcm_playback_handle = NULL;
|
||||
snd_pcm_close(handle);
|
||||
if (handle) {
|
||||
snd_pcm_close(handle);
|
||||
}
|
||||
atomic_store(&playback_stop_requested, 0);
|
||||
playback_initializing = 0;
|
||||
return -2;
|
||||
|
|
|
|||
Loading…
Reference in New Issue