# HG changeset patch # User Matti Hamalainen # Date 1559017520 -10800 # Node ID 781b1d63109a4d96f25c85ae4720d80f0962ba63 # Parent 3b5be00759edac1eb536c175b772046ea5a2ed29 Free previously allocated palette in the image palette allocation functions if it is not a constpal. diff -r 3b5be00759ed -r 781b1d63109a tools/lib64gfx.c --- a/tools/lib64gfx.c Mon May 27 12:22:08 2019 +0300 +++ b/tools/lib64gfx.c Tue May 28 07:25:20 2019 +0300 @@ -118,6 +118,14 @@ int dmSetDefaultC64Palette(DMImage *img) { int res; + + // Free previous palette + if (!img->constpal) + dmPaletteFree(img->pal); + + img->constpal = FALSE; + + // Allocate new if ((res = dmPaletteAlloc(&(img->pal), D64_NCOLORS, 255)) != DMERR_OK) return res; @@ -130,11 +138,18 @@ int dmSetMixedColorC64Palette(DMImage *img) { int res; + + // Free previous palette + if (!img->constpal) + dmPaletteFree(img->pal); + + img->constpal = FALSE; + + // Allocate new if ((res = dmPaletteAlloc(&(img->pal), D64_NCOLORS * D64_NCOLORS, -1)) != DMERR_OK) return res; - int n = 0; - for (int n1 = 0; n1 < D64_NCOLORS; n1++) + for (int n1 = 0, n = 0; n1 < D64_NCOLORS; n1++) { const DMColor *col1 = &dmDefaultC64Palette[n1]; for (int n2 = 0; n2 < D64_NCOLORS; n2++)