ref: e58330cb5be8f7bde57f1eacfca0c03467e21e0d
parent: 4219f692b155bf650c0918bffbbfa8d41dd670b6
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Thu Mar 12 08:45:47 EDT 2015
don't chanclose and only free chan if it's non nil
--- a/in_9.c
+++ b/in_9.c
@@ -270,8 +270,10 @@
threadkill(mtid);
mtid = -1;
}
- chanclose(kchan);
- chanfree(kchan);
+ if(kchan != nil){
+ chanfree(kchan);
+ kchan = nil;
+ }
mouseon = 0;
}
--- a/snd_9.c
+++ b/snd_9.c
@@ -5,7 +5,7 @@
#include "quakedef.h"
int audio_fd;
-int snd_inited;
+int sndon;
int wpos;
int stid = -1;
enum{
@@ -36,7 +36,7 @@
{
int i;
- snd_inited = 0;
+ sndon = 0;
if((audio_fd = open("/dev/audio", OWRITE)) < 0){
Con_Printf("Could not open /dev/audio: %r\n");
@@ -67,7 +67,7 @@
if((shm->buffer = mallocz(shm->samplebits/8 * shm->samples, 1)) == nil)
Sys_Error("SNDDMA_Init:mallocz: %r\n");
shm->samplepos = 0;
- snd_inited = 1;
+ sndon = 1;
schan = chancreate(sizeof(int), Nbuf);
if((stid = proccreate(sproc, nil, 8192)) < 0){
stid = -1;
@@ -79,7 +79,7 @@
int SNDDMA_GetDMAPos(void)
{
- if(!snd_inited)
+ if(!sndon)
return 0;
shm->samplepos = wpos / (shm->samplebits/8);
return shm->samplepos;
@@ -87,17 +87,20 @@
void SNDDMA_Shutdown(void)
{
- if(snd_inited){
- close(audio_fd);
- free(shm->buffer);
- if(stid != -1){
- threadkill(stid);
- stid = -1;
- }
- chanclose(schan);
+ if(!sndon)
+ return;
+
+ close(audio_fd);
+ free(shm->buffer);
+ if(stid != -1){
+ threadkill(stid);
+ stid = -1;
+ }
+ if(schan != nil){
chanfree(schan);
- snd_inited = 0;
+ schan = nil;
}
+ sndon = 0;
}
void SNDDMA_Submit(void)