diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2024-01-12 13:47:52 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-01-12 13:49:24 +0100 |
commit | 0ee745995b1f45ed321b0c20b151ec8e76e4344f (patch) | |
tree | 0369ee3a6a64cb594c11a241d4d000388ee39612 | |
parent | ed053de346d92c1a4218a7b80a20158f3535fe2a (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.cc | 2 |
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) |