From dc2c8dca5bafe537b446a80c333b77513eeaf765 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 19 Nov 2014 21:01:36 +0100 Subject: [PATCH] games/md, games/snes: fix memory leak on resize --- sys/src/games/md/md.c | 2 ++ sys/src/games/snes/snes.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sys/src/games/md/md.c b/sys/src/games/md/md.c index 97a39fe02..9c3a801ad 100644 --- a/sys/src/games/md/md.c +++ b/sys/src/games/md/md.c @@ -121,7 +121,9 @@ screeninit(void) originwindow(screen, Pt(0, 0), screen->r.min); p = divpt(addpt(screen->r.min, screen->r.max), 2); picr = (Rectangle){subpt(p, Pt(scale * 160, scale * 112)), addpt(p, Pt(scale * 160, scale * 112))}; + if(tmp != nil) freeimage(tmp); tmp = allocimage(display, Rect(0, 0, scale * 320, scale > 1 ? 1 : scale * 224), XRGB32, scale > 1, 0); + if(bg != nil) freeimage(bg); bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xCCCCCCFF); draw(screen, screen->r, bg, nil, ZP); } diff --git a/sys/src/games/snes/snes.c b/sys/src/games/snes/snes.c index d80cf08b1..b9a13023f 100644 --- a/sys/src/games/snes/snes.c +++ b/sys/src/games/snes/snes.c @@ -180,7 +180,9 @@ screeninit(void) p = divpt(addpt(screen->r.min, screen->r.max), 2); picr = (Rectangle){subpt(p, Pt(scale * 128, scale * 112)), addpt(p, Pt(scale * 128, scale * 127))}; + if(tmp != nil) freeimage(tmp); tmp = allocimage(display, Rect(0, 0, scale * 256, scale > 1 ? 1 : scale * 239), RGB15, scale > 1, 0); + if(bg != nil) freeimage(bg); bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xCCCCCCFF); draw(screen, screen->r, bg, nil, ZP); }