From: Jonathan Rajotte Date: Wed, 19 Jun 2019 17:28:14 +0000 (-0400) Subject: Fix: Unmap before truncating X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=a086573a88d37419d09d13e88be197d9467750b5 Fix: Unmap before truncating The mmap/mman compat layer for mingw uses the CreateFileMapping and UnmapViewOfFile thus implicitly imposes an order for truncation and ummapping [1]. For truncation calls, the underlying windows API call is SetEndOfFile. This function requires that the file be unmapped before being called [1]. [1] If CreateFileMapping is called to create a file mapping object for hFile, UnmapViewOfFile must be called first to unmap all views and call CloseHandle to close the file mapping object before you can call SetEndOfFile. [1] https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setendoffile#remarks Change-Id: Id4713ca3af612baa24e1fa4a749384eab452598a Signed-off-by: Jonathan Rajotte Reviewed-on: https://review.lttng.org/c/babeltrace/+/1519 Reviewed-by: Philippe Proulx Reviewed-by: Michael Jeanson --- diff --git a/src/ctfser/ctfser.c b/src/ctfser/ctfser.c index b28845cf..9152198f 100644 --- a/src/ctfser/ctfser.c +++ b/src/ctfser/ctfser.c @@ -144,6 +144,19 @@ int bt_ctfser_fini(struct bt_ctfser *ctfser) goto free_path; } + if (ctfser->base_mma) { + /* Unmap old base */ + ret = munmap_align(ctfser->base_mma); + if (ret) { + BT_LOGE_ERRNO("Failed to unmap stream file", + ": ret=%d, size-bytes=%" PRIu64, + ret, ctfser->stream_size_bytes); + goto end; + } + + ctfser->base_mma = NULL; + } + /* * Truncate the stream file's size to the minimum required to * fit the last packet as we might have grown it too much during @@ -160,18 +173,6 @@ int bt_ctfser_fini(struct bt_ctfser *ctfser) goto end; } - if (ctfser->base_mma) { - /* Unmap old base */ - ret = munmap_align(ctfser->base_mma); - if (ret) { - BT_LOGE_ERRNO("Failed to unmap stream file", - ": ret=%d, size-bytes=%" PRIu64, - ret, ctfser->stream_size_bytes); - goto end; - } - - ctfser->base_mma = NULL; - } ret = close(ctfser->fd); if (ret) {