Skip to content

Commit 192c409

Browse files
committed
Ensure new/delete tracked
1 parent 5839dcb commit 192c409

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

‎Makefile‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
LD_FLAGS+= -L$(V8_PATH)/out.gn/x64.release.sample/obj/ -lv8_monolith -lpthread -lstdc++fs
1+
2+
# Note: -Bsymbolic is necessary to ensure new/delete goes through the overrides in new.cpp and is tracked
3+
LD_FLAGS+= -L$(V8_PATH)/out.gn/x64.release.sample/obj/ -lv8_monolith -lpthread -lstdc++fs -static-libstdc++ -Wl,-Bsymbolic
24
CXX_FLAGS+= -std=c++17 -fvisibility=hidden -fPIC -O2 -g -isystem $(V8_PATH)/include -DV8_COMPRESS_POINTERS
35

4-
MODULE_OBJS = js.o module.o sha256.o
6+
MODULE_OBJS = js.o module.o sha256.o new.o
57

68
modjs.so: $(MODULE_OBJS) | check-env
79
$(CXX) -shared -o $@ $^ $(LD_FLAGS)

‎new.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <cstddef> // std::size_t
2+
#include <new>
3+
4+
extern void *(*RedisModule_Alloc)(size_t bytes);
5+
extern void (*RedisModule_Free)(void *ptr);
6+
extern void *(*RedisModule_Calloc)(size_t nmemb, size_t size);
7+
8+
void *operator new(size_t size)
9+
{
10+
return RedisModule_Alloc(size);
11+
}
12+
13+
void* operator new(std::size_t size, const std::nothrow_t&)
14+
{
15+
return RedisModule_Alloc(size);
16+
}
17+
18+
void operator delete(void * p) noexcept
19+
{
20+
RedisModule_Free(p);
21+
}
22+
23+
void operator delete(void *p, std::size_t) noexcept
24+
{
25+
RedisModule_Free(p);
26+
}

0 commit comments

Comments
 (0)