Fix some segfaults for kits with invalid instrument entries. Also fix a couple in internal segfaults.

This commit is contained in:
Nick Lanham 2012-02-07 12:22:26 +01:00
parent a2e14e6652
commit 9c1e713914
3 changed files with 19 additions and 6 deletions

16
drmr.c
View File

@ -35,7 +35,7 @@ int load_sample(char* path, drmr_sample* samp) {
sndf = sf_open(path,SFM_READ,&(samp->info));
if (!sndf) {
fprintf(stderr,"Failed to open sound file: %s\n",sf_strerror(sndf));
fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf));
return 1;
}
@ -63,7 +63,12 @@ static void* load_thread(void* arg) {
for(;;) {
pthread_cond_wait(&drmr->load_cond,
&drmr->load_mutex);
load_hydrogen_kit(drmr,drmr->kits->kits[drmr->curKit].path);
if (drmr->curKit >= drmr->kits->num_kits) {
int os = drmr->num_samples;
drmr->num_samples = 0;
if (os > 0) free_samples(drmr->samples,os);
} else
load_hydrogen_kit(drmr,drmr->kits->kits[drmr->curKit].path);
}
pthread_mutex_unlock(&drmr->load_mutex);
return 0;
@ -118,6 +123,7 @@ instantiate(const LV2_Descriptor* descriptor,
free(drmr);
return 0;
}
drmr->samples = NULL; // prevent attempted freeing in load
load_hydrogen_kit(drmr,drmr->kits->kits->path);
drmr->curKit = 0;
@ -247,7 +253,11 @@ static void run(LV2_Handle instance, uint32_t n_samples) {
int pos,lim;
drmr_sample* cs = drmr->samples+i;
if (cs->active) {
float gain = *(drmr->gains[i]);
float gain;
if (i < 16)
gain = *(drmr->gains[i]);
else
gain = 1.0f;
one_active = 1;
if (cs->info.channels == 1) { // play mono sample
lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset));

View File

@ -112,8 +112,10 @@ endElement(void *userData, const char *name)
info->cur_off = 0;
if (!info->scan_only && info->in_instrument && !strcmp(name,"instrument")) {
// ending an instrument, add current struct to end of list
if (!info->scan_only &&
info->in_instrument &&
!strcmp(name,"instrument") &&
info->cur_instrument->filename) {
struct instrument_info * cur_i = info->kit_info->instruments;
if (cur_i) {
while(cur_i->next) cur_i = cur_i->next;
@ -249,7 +251,7 @@ kits* scan_kits() {
return ret;
}
static void free_samples(drmr_sample* samples, int num_samples) {
void free_samples(drmr_sample* samples, int num_samples) {
int i;
for (i=0;i<num_samples;i++)
free(samples[i].data);

View File

@ -4,6 +4,7 @@
#define DRMR_HYDRO_H
kits* scan_kits();
void free_samples(drmr_sample* samples, int num_samples);
int load_hydrogen_kit(DrMr* drmr, char* path);
#endif // DRMR_HYDRO_H