From b28273294da0212bd4f9cd0dcc21d53713fd423d Mon Sep 17 00:00:00 2001 From: Kentaro Sato Date: Sun, 23 May 2010 08:32:43 +0000 Subject: [PATCH] Fix infinite loop on reusing soundfont struct. --- ChangeLog | 2 ++ timidity/sndfont.c | 35 ++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36285c3d..b6dd844d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * timidity/readmidi.c, timidity/reverb.[ch]: Fix ch_3tap_delay crash. + * timidity/sndfont.c: + Fix infinite loop on reusing soundfont struct. 2010-05-17 Eric A. Welsh diff --git a/timidity/sndfont.c b/timidity/sndfont.c index 98b8b644..d2f80c9d 100644 --- a/timidity/sndfont.c +++ b/timidity/sndfont.c @@ -232,20 +232,29 @@ static SFInsts *find_soundfont(char *sf_file) static SFInsts *new_soundfont(char *sf_file) { - SFInsts *sf; + SFInsts *sf, *prev; - sf_file = FILENAME_NORMALIZE(sf_file); - for(sf = sfrecs; sf != NULL; sf = sf->next) - if(sf->fname == NULL) - break; - if(sf == NULL) - sf = (SFInsts *)safe_malloc(sizeof(SFInsts)); - memset(sf, 0, sizeof(SFInsts)); - init_mblock(&sf->pool); - sf->fname = SFStrdup(sf, FILENAME_NORMALIZE(sf_file)); - sf->def_order = DEFAULT_SOUNDFONT_ORDER; - sf->amptune = 1.0; - return sf; + sf_file = FILENAME_NORMALIZE(sf_file); + for(sf = sfrecs, prev = NULL; sf != NULL; prev = sf, sf = sf->next) + { + if(sf->fname == NULL) + { + /* remove the record from the chain to reuse */ + if (prev != NULL) + prev->next = sf->next; + else if (sfrecs == sf) + sfrecs = sf->next; + break; + } + } + if(sf == NULL) + sf = (SFInsts *)safe_malloc(sizeof(SFInsts)); + memset(sf, 0, sizeof(SFInsts)); + init_mblock(&sf->pool); + sf->fname = SFStrdup(sf, FILENAME_NORMALIZE(sf_file)); + sf->def_order = DEFAULT_SOUNDFONT_ORDER; + sf->amptune = 1.0; + return sf; } void add_soundfont(char *sf_file, -- 2.11.0