You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I discovered this issue while using valgrind. On serving a file using serveStaticFile valgrind reports an invalid read of size 4 whenever the refcount of a FreeListRef is accessed.
I read the source code. It seems that the "+ int.sizeof" to allocate memory for storing ref count got lost with commit 6be5471 .
As far as I figured out:
the memory for FreeListRef is allocated by calling FreeListObjectAlloc
AllocSize is just the size of T (or the classInstanceSize if T is a class), so no memory for storing the refcount is allocated (line 672)
I have no time to figure out where the "+ int.sizeof" fits best (and therefore, can't create a PR).
Valgrind output:
==5411== Invalid write of size 4
==5411== at 0xC97B52: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef11T6opCallZ6opCallFNbZS4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:694) ==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd ==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
==5411==
==5411== Invalid read of size 4
==5411== at 0xC97AC2: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef15checkInvariantsMxFNaNbNiZv (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:753) ==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd ==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
==5411==
==5411== Invalid read of size 4
==5411== at 0xC97988: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef5clearMFNbNiZv (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:732) ==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd ==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
==5411==
==5411== Invalid read of size 4
==5411== at 0xC9798A: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef5clearMFNbNiZv (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:732) ==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd ==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
The text was updated successfully, but these errors were encountered:
…ef count. Fixes#1432.
Commit 6be5471 switched FreeListRef to use FreeListObjectAlloc underneath, but didn't accound for the extra memory that is needed to store the reference count directly after the object payload. The possible implications of this are memory corruption and memory leaks, although with the predefined allocator setip, this will only happen to types with a POT size or slightly less.
This commit adds an "EXTRA" template type parameter to FreeListObjectAlloc that is used to determine the additional amount of allocated memory, which is set to "int" in the case of FreeListRef.
(cherry picked from commit d78a9ce)
…ef count. Fixes#1432.
Commit 6be5471 switched FreeListRef to use FreeListObjectAlloc underneath, but didn't accound for the extra memory that is needed to store the reference count directly after the object payload. The possible implications of this are memory corruption and memory leaks, although with the predefined allocator setip, this will only happen to types with a POT size or slightly less.
This commit adds an "EXTRA" template type parameter to FreeListObjectAlloc that is used to determine the additional amount of allocated memory, which is set to "int" in the case of FreeListRef.
(cherry picked from commit d78a9ce)
(cherry picked from commit 613d159)
I discovered this issue while using valgrind. On serving a file using serveStaticFile valgrind reports an invalid read of size 4 whenever the refcount of a FreeListRef is accessed.
I read the source code. It seems that the "+ int.sizeof" to allocate memory for storing ref count got lost with commit 6be5471 .
As far as I figured out:
I have no time to figure out where the "+ int.sizeof" fits best (and therefore, can't create a PR).
Valgrind output:
==5411== Invalid write of size 4
==5411== at 0xC97B52: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef11T6opCallZ6opCallFNbZS4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:694)
==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd
==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
==5411==
==5411== Invalid read of size 4
==5411== at 0xC97AC2: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef15checkInvariantsMxFNaNbNiZv (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:753)
==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd
==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
==5411==
==5411== Invalid read of size 4
==5411== at 0xC97988: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef5clearMFNbNiZv (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:732)
==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd
==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
==5411==
==5411== Invalid read of size 4
==5411== at 0xC9798A: D4vibe5utils6memory110T11FreeListRefTS4vibe4core6stream12OutputStream12writeDefaultMFC4vibe4core6stream11InputStreammZ6BufferVbi0Z11FreeListRef5clearMFNbNiZv (../../.dub/packages/vibe-d-0.7.27/source/vibe/utils/memory.d:732)
==5411== Address 0x1899e270 is 0 bytes after a block of size 65,552 alloc'd
==5411== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreloadmemcheck-amd64-linux.so)
The text was updated successfully, but these errors were encountered: