Commits

Anonymous committed c19b370

Don't leak memory in XEmacs with huge log files, ERC.

  • Participants
  • Parent commits 70db8ae

Comments (0)

Files changed (2)

+2009-07-22  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* erc-log.el (erc-log-setup-logging): 
+	Don't insert the entire log file into the buffer if
+	erc-truncate-buffer is in erc-insert-post-hook (even though most
+	of the buffer is later deleted in this case); avoids XEmacs
+	keeping lots of memory around needlessly when log files are huge
+	but buffer sizes are tiny. GNU Emacs doesn't do this, but it
+	should be a win there too, there's no need to create a 100 MB
+	buffer needlessly. 
+
 2008-07-23  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 0.22 released.
 	   (set (make-local-variable 'write-file-hooks)
 		'(erc-save-buffer-in-logs))))
     (when erc-log-insert-log-on-open
-      (ignore-errors (insert-file-contents (erc-current-logfile))
-		     (move-marker erc-last-saved-position
-				  (1- (point-max)))))))
+      (let* ((log-file (erc-current-logfile))
+             (log-file-size (nth 7 (file-attributes log-file)))
+             (start (if (and log-file-size
+                             (memq 'erc-truncate-buffer
+				   erc-insert-post-hook))
+                        (- log-file-size erc-max-buffer-size)
+                      0)))
+        (ignore-errors (insert-file-contents log-file nil start
+                                             log-file-size))
+        (move-marker erc-last-saved-position
+                      (1- (point-max)))))))
 
 ;;; Append, so that 'erc-initialize-log-marker keeps running first.
 (add-hook 'erc-connect-pre-hook 'erc-log-setup-logging 'append)