Skip to content

Commit fb67900

Browse files
committed
fix: address use-after-free issue in debug code
1 parent f421b10 commit fb67900

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

backend/lib/alloc.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// balboa
2-
// Copyright (c) 2018, 2019 DCSO GmbH
2+
// Copyright (c) 2018, 2026 DCSO GmbH
33

44
#ifndef __ALLOC_H
55
#define __ALLOC_H
@@ -10,8 +10,10 @@
1010

1111
static inline void* blb_realloc_impl(
1212
const char* name, void* p, size_t new_size) {
13+
uintptr_t old_addr = (uintptr_t)p;
1314
void* pp = realloc(p, new_size);
14-
X(log_debug("(%s) realloc `%p` `%p` `%zu`", name, p, pp, new_size));
15+
X(log_debug(
16+
"(%s) realloc `0x%" PRIxPTR "` `%p` `%zu`", name, old_addr, pp, new_size));
1517
return (pp);
1618
}
1719

@@ -32,8 +34,9 @@ static inline void* blb_realloc_impl(
3234
#define blb_realloc(p, sz) \
3335
({ \
3436
size_t p_sz = (sz); \
37+
uintptr_t old_addr = (uintptr_t)(p); \
3538
void* pp = realloc((p), p_sz); \
36-
X(log_debug("realloc `%p` `%zu` `%p`", pp, p_sz, p)); \
39+
X(log_debug("realloc `0x%" PRIxPTR "` `%zu` `%p`", old_addr, p_sz, pp)); \
3740
pp; \
3841
})
3942
#define blb_free(p) \
@@ -42,4 +45,4 @@ static inline void* blb_realloc_impl(
4245
free(p); \
4346
} while(0)
4447

45-
#endif
48+
#endif

0 commit comments

Comments
 (0)