Skip to content

Commit 5b25dc6

Browse files
committed
MDEV-17248 Improve ASAN memory pool instrumentation
alloc_root(): unpoison only requested amount of bytes instead of a possible bigger aligned-sized buffer.
1 parent e43bc02 commit 5b25dc6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

include/my_valgrind.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
#endif /* HAVE_VALGRIND */
5050

5151
#ifndef DBUG_OFF
52-
#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED(A,B); memset(A,C,B); } while(0)
52+
#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
5353
#else
54-
#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED(A,B); } while(0)
54+
#define TRASH_FILL(A,B,C) do { const size_t trash_tmp __attribute__((unused))= (B); MEM_UNDEFINED(A,trash_tmp); } while (0)
5555
#endif
5656
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
5757
#define TRASH_FREE(A,B) do { TRASH_FILL(A,B,0x8F); MEM_NOACCESS(A,B); } while(0)

mysys/my_alloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
184184
uchar* point;
185185
reg1 USED_MEM *next= 0;
186186
reg2 USED_MEM **prev;
187+
size_t original_length = length;
187188
DBUG_ENTER("alloc_root");
188189
DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root));
189190
DBUG_ASSERT(alloc_root_inited(mem_root));
@@ -241,7 +242,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
241242
mem_root->used= next;
242243
mem_root->first_block_usage= 0;
243244
}
244-
TRASH_ALLOC(point, length);
245+
TRASH_ALLOC(point, original_length);
245246
DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point));
246247
DBUG_RETURN((void*) point);
247248
#endif

0 commit comments

Comments
 (0)