summaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2018-03-30 16:44:24 -0400
committerNoam Postavsky <npostavs@gmail.com>2018-06-03 12:48:13 -0400
commitdaa602338fd91aced720b5555c8b6ed389383831 (patch)
treeb859b9a568d8b18d0f67cdfeee62c93a3bbcc299 /test/src
parent7460840a6c9ab713e8ccc470011495fdb86a61d7 (diff)
downloademacs-daa602338fd91aced720b5555c8b6ed389383831.tar.gz
emacs-daa602338fd91aced720b5555c8b6ed389383831.tar.bz2
emacs-daa602338fd91aced720b5555c8b6ed389383831.zip
Fix another case of freed markers in the undo-list (Bug#30931)
* src/alloc.c (free_marker): Remove. * src/editfns.c (save_restriction_restore): * src/insdel.c (signal_before_change): Detach the markers from the buffer when we're done with them instead of calling free_marker on them. * test/src/editfns-tests.el (delete-region-undo-markers-1) (delete-region-undo-markers-2): New tests. (cherry picked from commit 96b8747d5c5d747af13fd84d8fe0308ef2a0ea7a)
Diffstat (limited to 'test/src')
-rw-r--r--test/src/editfns-tests.el51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index b72f37d1f01..714e92e5053 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -247,4 +247,55 @@
(buffer-string)
"foo bar baz qux"))))))
+(ert-deftest delete-region-undo-markers-1 ()
+ "Make sure we don't end up with freed markers reachable from Lisp."
+ ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40
+ (with-temp-buffer
+ (insert "1234567890")
+ (setq buffer-undo-list nil)
+ (narrow-to-region 2 5)
+ ;; `save-restriction' in a narrowed buffer creates two markers
+ ;; representing the current restriction.
+ (save-restriction
+ (widen)
+ ;; Any markers *within* the deleted region are put onto the undo
+ ;; list.
+ (delete-region 1 6))
+ ;; (princ (format "%S" buffer-undo-list) #'external-debugging-output)
+ ;; `buffer-undo-list' is now
+ ;; (("12345" . 1) (#<temp-marker1> . -1) (#<temp-marker2> . 1))
+ ;;
+ ;; If temp-marker1 or temp-marker2 are freed prematurely, calling
+ ;; `type-of' on them will cause Emacs to abort. Calling
+ ;; `garbage-collect' will also abort if it finds any reachable
+ ;; freed objects.
+ (should (eq (type-of (car (nth 1 buffer-undo-list))) 'marker))
+ (should (eq (type-of (car (nth 2 buffer-undo-list))) 'marker))
+ (garbage-collect)))
+
+(ert-deftest delete-region-undo-markers-2 ()
+ "Make sure we don't end up with freed markers reachable from Lisp."
+ ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#55
+ (with-temp-buffer
+ (insert "1234567890")
+ (setq buffer-undo-list nil)
+ ;; signal_before_change creates markers delimiting a change
+ ;; region.
+ (let ((before-change-functions
+ (list (lambda (beg end)
+ (delete-region (1- beg) (1+ end))))))
+ (delete-region 2 5))
+ ;; (princ (format "%S" buffer-undo-list) #'external-debugging-output)
+ ;; `buffer-undo-list' is now
+ ;; (("678" . 1) ("12345" . 1) (#<marker in no buffer> . -1)
+ ;; (#<temp-marker1> . -1) (#<temp-marker2> . -4))
+ ;;
+ ;; If temp-marker1 or temp-marker2 are freed prematurely, calling
+ ;; `type-of' on them will cause Emacs to abort. Calling
+ ;; `garbage-collect' will also abort if it finds any reachable
+ ;; freed objects.
+ (should (eq (type-of (car (nth 3 buffer-undo-list))) 'marker))
+ (should (eq (type-of (car (nth 4 buffer-undo-list))) 'marker))
+ (garbage-collect)))
+
;;; editfns-tests.el ends here