]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: sink: make sure to always properly unmap a file-backed ring
authorWilly Tarreau <w@1wt.eu>
Tue, 24 Jan 2023 11:11:41 +0000 (12:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 24 Jan 2023 11:11:41 +0000 (12:11 +0100)
The munmap() call performed on exit was incorrect since it used to apply
to the buffer instead of the area, so neither the pointer nor the size
were page-aligned. This patches corrects this and also adds a call to
msync() since munmap() alone doesn't guarantee that data will be dumped.

This should be backported to 2.6.

src/sink.c

index 862a1ae322837285ff8e028dd16cc7f91c828853..0aae5f2a7e74e91ad6405b653c261bf91b216053 100644 (file)
@@ -1392,8 +1392,13 @@ static void sink_deinit()
 
        list_for_each_entry_safe(sink, sb, &sink_list, sink_list) {
                if (sink->type == SINK_TYPE_BUFFER) {
-                       if (sink->store)
-                               munmap(sink->ctx.ring->buf.area, sink->ctx.ring->buf.size);
+                       if (sink->store) {
+                               size_t size = (sink->ctx.ring->buf.size + 4095UL) & -4096UL;
+                               void *area = (sink->ctx.ring->buf.area - sizeof(*sink->ctx.ring));
+
+                               msync(area, size, MS_SYNC);
+                               munmap(area, size);
+                       }
                        else
                                ring_free(sink->ctx.ring);
                }