From: malc Date: Tue, 30 Oct 2012 00:31:19 +0000 (+0400) Subject: Avoid leaking memory under certain conditions X-Git-Tag: v14~103 X-Git-Url: https://repo.or.cz/w/llpp.git/commitdiff_plain/37b0f8b15449c52c7665ccaf39c26cab65dbcff6 Avoid leaking memory under certain conditions When document is loaded pages that are already rendered are not immediately freed, futhermore the eviction will not happen given that old pages occupy the same spot and are not considered as eviction targets, generation count is not checked and even if it was eviting old page with the new underlying document can be unsafe (depends on how the underlying rendering engine is implemented), so the safest way to deal with it is to just flush them en masse. --- diff --git a/main.ml b/main.ml index c7707f9..5f9e16d 100644 --- a/main.ml +++ b/main.ml @@ -1838,12 +1838,20 @@ let invalidate s f = state.geomcmds <- ps, ((s, f) :: cmds); ;; +let flushpages () = + Hashtbl.iter (fun _ opaque -> + wcmd "freepage %s" opaque; + ) state.pagemap; + Hashtbl.clear state.pagemap; +;; + let opendoc path password = state.path <- path; state.password <- password; state.gen <- state.gen + 1; state.docinfo <- []; + flushpages (); setaalevel conf.aalevel; Wsi.settitle ("llpp " ^ Filename.basename path); wcmd "open %s\000%s\000" path password; @@ -2589,10 +2597,7 @@ let settrim trimmargins trimfuzz = invalidate "settrim" (fun () -> wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins) x0 y0 x1 y1); - Hashtbl.iter (fun _ opaque -> - wcmd "freepage %s" opaque; - ) state.pagemap; - Hashtbl.clear state.pagemap; + flushpages (); ;; let setzoom zoom =