(unless (which "strace")
(test-skip 1))
(test-equal "manual munmap does not lead to double free"
1 (begin
(define mmap-address #f)
(call-with-output-file temp-file
(lambda (p)
(display "something interesting\n" p)))
(sync)
(system (string-append "strace -o " strace-output
" -p " (number->string (getpid))
" -e trace=munmap &"))
(let* ((bv (file->bytevector temp-file))
(address (pk 'addr (pointer-address (pk 'ptr: (bytevector->pointer bv))))))
(set! mmap-address address)
(munmap bv))
(gc) (sync)
(let ((text (pk 'text (call-with-input-file strace-output get-string-all)))
(pattern (pk 'pattern (format #f "munmap(0x~x" mmap-address))))
(length (filter (cut string-prefix-ci? pattern <>)
(pk 'lines (string-split text #\newline)))))))