Fix crash on switching sound in Vista
[xboard.git] / winboard / winboard.c
index b5ba50d..b86a399 100644 (file)
@@ -5621,7 +5621,7 @@ MyLoadSound(MySound *ms)
   struct stat st;\r
   FILE *f;\r
 \r
-  if (ms->data) free(ms->data);\r
+  if (ms->data && ms->flag) free(ms->data);\r
   ms->data = NULL;\r
 \r
   switch (ms->name[0]) {\r
@@ -5642,6 +5642,7 @@ MyLoadSound(MySound *ms)
       HANDLE h = FindResource(hInst, ms->name + 1, "WAVE");\r
       if (h == NULL) break;\r
       ms->data = (void *)LoadResource(hInst, h);\r
+      ms->flag = 0; // not maloced, so cannot be freed!\r
       if (h == NULL) break;\r
       ok = TRUE;\r
     }\r
@@ -5652,6 +5653,7 @@ MyLoadSound(MySound *ms)
     if (f == NULL) break;\r
     if (fstat(fileno(f), &st) < 0) break;\r
     ms->data = malloc(st.st_size);\r
+    ms->flag = 1;\r
     if (fread(ms->data, st.st_size, 1, f) < 1) break;\r
     fclose(f);\r
     ok = TRUE;\r