summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-01-12 13:47:52 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2024-01-12 13:49:24 +0100
commit0ee745995b1f45ed321b0c20b151ec8e76e4344f (patch)
tree0369ee3a6a64cb594c11a241d4d000388ee39612
parented053de346d92c1a4218a7b80a20158f3535fe2a (diff)
pkgcachegen: Use placement new to construct header
Avoid copying the header from a stack allocated object as this will copy uninitialized padding bytes into the cache, triggering valgrind errors which people then use as a strawman for unrelated errors on armhf. In an optimal world we should annotate the allocator however such that valgrind actually does treat those bytes as uninitialized and then supress warnings in the harmless places, such that when you then go and try to access it in a place that matters, you do get an error for uninitialized memory. Currently any access within the pool will be considered initialized which is clearly suboptimal. But this is very much a TBD topic and involves annotating the allocator everywhere.
-rw-r--r--apt-pkg/pkgcachegen.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 9e47ef369..3a85a9585 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -89,7 +89,7 @@ bool pkgCacheGenerator::Start()
Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
// Starting header
- *Cache.HeaderP = pkgCache::Header();
+ new (Cache.HeaderP) pkgCache::Header();
// make room for the hashtables for packages and groups
if (Map.RawAllocate(2 * (Cache.HeaderP->GetHashTableSize() * sizeof(map_pointer<void>))) == 0)