From 9e82e6c5e9f309f3ca1c3b0f38cdce2cfdcfa31d Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 14 Jun 2011 12:40:11 +0200 Subject: [PATCH] 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. --- winboard/winboard.c | 4 +++- winboard/winboard.h | 1 + 2 files changed, 4 insertions(+), 1 deletions(-) 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 { -- 1.7.0.4