tpage: add missing delayfreeimage calls - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 94349f64d16ed2159cc944a2af7a3fcaedd9c9d9
parent d19fdc056d160a429d046e472287073edec11ea3
Author: Fazlul Shahriar 
Date:   Sat, 15 Aug 2009 02:34:42 -0400

page: add missing delayfreeimage calls

fixes #19 http://code.swtch.com/plan9port/issue/19

http://codereview.appspot.com/108041

Diffstat:
  M src/cmd/page/view.c                 |      16 ++++++++++++++--

1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/cmd/page/view.c b/src/cmd/page/view.c
t@@ -18,6 +18,7 @@
 Document *doc;
 Mousectl *mc;
 Image *im;
+Image *tofree;
 int page;
 int angle = 0;
 int showbottom = 0;                /* on the next showpage, move the image so the bottom is visible. */
t@@ -62,6 +63,16 @@ enum {
         RMenu = 3,
 };
 
+static void
+delayfreeimage(Image *m)
+{
+        if(m == tofree)
+                return;
+        if(tofree)
+                freeimage(tofree);
+        tofree = m;
+}
+
 void
 unhide(void)
 {
t@@ -121,6 +132,7 @@ showpage(int page, Menu *m)
                 m->lasthit = reverse ? doc->npage-1-page : page;
         
         setcursor(mc, &reading);
+        delayfreeimage(nil);
         im = cachedpage(doc, angle, page);
         if(im == nil)
                 wexits(0);
t@@ -553,8 +565,8 @@ viewer(Document *dd)
                                                         wexits("memory");
                                                 }
                                                 resample(im, tmp);
-                                                freeimage(im);
                                                 im = tmp;
+                                                delayfreeimage(tmp);
                                                 setcursor(mc, nil);
                                                 ul = screen->r.min;
                                                 redraw(screen);
t@@ -578,8 +590,8 @@ viewer(Document *dd)
                                                         wexits("memory");
                                                 }
                                                 resample(im, tmp);
-                                                freeimage(im);
                                                 im = tmp;
+                                                delayfreeimage(tmp);
                                                 setcursor(mc, nil);
                                                 ul = screen->r.min;
                                                 redraw(screen);