aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorNoam Postavsky2018-03-30 16:44:24 -0400
committerNoam Postavsky2018-06-03 12:48:13 -0400
commitdaa602338fd91aced720b5555c8b6ed389383831 (patch)
treeb859b9a568d8b18d0f67cdfeee62c93a3bbcc299 /test/src
parent7460840a6c9ab713e8ccc470011495fdb86a61d7 (diff)
downloademacs-daa602338fd91aced720b5555c8b6ed389383831.tar.gz
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 @@
247 (buffer-string) 247 (buffer-string)
248 "foo bar baz qux")))))) 248 "foo bar baz qux"))))))
249 249
250(ert-deftest delete-region-undo-markers-1 ()
251 "Make sure we don't end up with freed markers reachable from Lisp."
252 ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40
253 (with-temp-buffer
254 (insert "1234567890")
255 (setq buffer-undo-list nil)
256 (narrow-to-region 2 5)
257 ;; `save-restriction' in a narrowed buffer creates two markers
258 ;; representing the current restriction.
259 (save-restriction
260 (widen)
261 ;; Any markers *within* the deleted region are put onto the undo
262 ;; list.
263 (delete-region 1 6))
264 ;; (princ (format "%S" buffer-undo-list) #'external-debugging-output)
265 ;; `buffer-undo-list' is now
266 ;; (("12345" . 1) (#<temp-marker1> . -1) (#<temp-marker2> . 1))
267 ;;
268 ;; If temp-marker1 or temp-marker2 are freed prematurely, calling
269 ;; `type-of' on them will cause Emacs to abort. Calling
270 ;; `garbage-collect' will also abort if it finds any reachable
271 ;; freed objects.
272 (should (eq (type-of (car (nth 1 buffer-undo-list))) 'marker))
273 (should (eq (type-of (car (nth 2 buffer-undo-list))) 'marker))
274 (garbage-collect)))
275
276(ert-deftest delete-region-undo-markers-2 ()
277 "Make sure we don't end up with freed markers reachable from Lisp."
278 ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#55
279 (with-temp-buffer
280 (insert "1234567890")
281 (setq buffer-undo-list nil)
282 ;; signal_before_change creates markers delimiting a change
283 ;; region.
284 (let ((before-change-functions
285 (list (lambda (beg end)
286 (delete-region (1- beg) (1+ end))))))
287 (delete-region 2 5))
288 ;; (princ (format "%S" buffer-undo-list) #'external-debugging-output)
289 ;; `buffer-undo-list' is now
290 ;; (("678" . 1) ("12345" . 1) (#<marker in no buffer> . -1)
291 ;; (#<temp-marker1> . -1) (#<temp-marker2> . -4))
292 ;;
293 ;; If temp-marker1 or temp-marker2 are freed prematurely, calling
294 ;; `type-of' on them will cause Emacs to abort. Calling
295 ;; `garbage-collect' will also abort if it finds any reachable
296 ;; freed objects.
297 (should (eq (type-of (car (nth 3 buffer-undo-list))) 'marker))
298 (should (eq (type-of (car (nth 4 buffer-undo-list))) 'marker))
299 (garbage-collect)))
300
250;;; editfns-tests.el ends here 301;;; editfns-tests.el ends here