From: H.G. Muller Date: Tue, 14 Jun 2011 10:40:11 +0000 (+0200) Subject: Fix crash on switching sound in Vista X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=9e82e6c5e9f309f3ca1c3b0f38cdce2cfdcfa31d;p=xboard.git Fix crash on switching sound in Vista When choosing a new sound the wave form of the old one was free'ed, but because built-in sounds are not really malloc'ed, this led to a crash. --- diff --git a/winboard/winboard.c b/winboard/winboard.c index b5ba50d..b86a399 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -5621,7 +5621,7 @@ MyLoadSound(MySound *ms) struct stat st; FILE *f; - if (ms->data) free(ms->data); + if (ms->data && ms->flag) free(ms->data); ms->data = NULL; switch (ms->name[0]) { @@ -5642,6 +5642,7 @@ MyLoadSound(MySound *ms) HANDLE h = FindResource(hInst, ms->name + 1, "WAVE"); if (h == NULL) break; ms->data = (void *)LoadResource(hInst, h); + ms->flag = 0; // not maloced, so cannot be freed! if (h == NULL) break; ok = TRUE; } @@ -5652,6 +5653,7 @@ MyLoadSound(MySound *ms) if (f == NULL) break; if (fstat(fileno(f), &st) < 0) break; ms->data = malloc(st.st_size); + ms->flag = 1; if (fread(ms->data, st.st_size, 1, f) < 1) break; fclose(f); ok = TRUE; diff --git a/winboard/winboard.h b/winboard/winboard.h index 89c50ab..3ac652c 100644 --- a/winboard/winboard.h +++ b/winboard/winboard.h @@ -85,6 +85,7 @@ typedef struct { typedef struct { char* name; void* data; + int flag; // [HGM] needed to indicate if data was malloc'ed or not } MySound; typedef struct {