aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorNoam Postavsky2018-03-30 16:44:24 -0400
committerPaul Eggert2018-03-30 14:26:25 -0700
commit96b8747d5c5d747af13fd84d8fe0308ef2a0ea7a (patch)
tree1b7cd8463b098f6386b0b8be81f1ab755b6308b9 /test/src
parent842b3d7412eaed6b2c9f90c3361abb4932ec0b1d (diff)
downloademacs-96b8747d5c5d747af13fd84d8fe0308ef2a0ea7a.tar.gz
emacs-96b8747d5c5d747af13fd84d8fe0308ef2a0ea7a.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.
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 442ad089375..2e20c9dd126 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -288,4 +288,55 @@
288 (buffer-string) 288 (buffer-string)
289 "foo bar baz qux")))))) 289 "foo bar baz qux"))))))
290 290
291(ert-deftest delete-region-undo-markers-1 ()
292 "Make sure we don't end up with freed markers reachable from Lisp."
293 ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40
294 (with-temp-buffer
295 (insert "1234567890")
296 (setq buffer-undo-list nil)
297 (narrow-to-region 2 5)
298 ;; `save-restriction' in a narrowed buffer creates two markers
299 ;; representing the current restriction.
300 (save-restriction
301 (widen)
302 ;; Any markers *within* the deleted region are put onto the undo
303 ;; list.
304 (delete-region 1 6))
305 ;; (princ (format "%S" buffer-undo-list) #'external-debugging-output)
306 ;; `buffer-undo-list' is now
307 ;; (("12345" . 1) (#<temp-marker1> . -1) (#<temp-marker2> . 1))
308 ;;
309 ;; If temp-marker1 or temp-marker2 are freed prematurely, calling
310 ;; `type-of' on them will cause Emacs to abort. Calling
311 ;; `garbage-collect' will also abort if it finds any reachable
312 ;; freed objects.
313 (should (eq (type-of (car (nth 1 buffer-undo-list))) 'marker))
314 (should (eq (type-of (car (nth 2 buffer-undo-list))) 'marker))
315 (garbage-collect)))
316
317(ert-deftest delete-region-undo-markers-2 ()
318 "Make sure we don't end up with freed markers reachable from Lisp."
319 ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#55
320 (with-temp-buffer
321 (insert "1234567890")
322 (setq buffer-undo-list nil)
323 ;; signal_before_change creates markers delimiting a change
324 ;; region.
325 (let ((before-change-functions
326 (list (lambda (beg end)
327 (delete-region (1- beg) (1+ end))))))
328 (delete-region 2 5))
329 ;; (princ (format "%S" buffer-undo-list) #'external-debugging-output)
330 ;; `buffer-undo-list' is now
331 ;; (("678" . 1) ("12345" . 1) (#<marker in no buffer> . -1)
332 ;; (#<temp-marker1> . -1) (#<temp-marker2> . -4))
333 ;;
334 ;; If temp-marker1 or temp-marker2 are freed prematurely, calling
335 ;; `type-of' on them will cause Emacs to abort. Calling
336 ;; `garbage-collect' will also abort if it finds any reachable
337 ;; freed objects.
338 (should (eq (type-of (car (nth 3 buffer-undo-list))) 'marker))
339 (should (eq (type-of (car (nth 4 buffer-undo-list))) 'marker))
340 (garbage-collect)))
341
291;;; editfns-tests.el ends here 342;;; editfns-tests.el ends here