Commit 692a99ce authored by Anton Likhtarov's avatar Anton Likhtarov Committed by Andrii Grynenko

Add extra assertions in ExternalUnixAddr::free()

Summary: Memory corruption investigation

Test Plan: fbconfig folly/test:network_address_test; fbmake runtests

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, andrii, njormrod

FB internal diff: D1592539

Tasks: 5230657

Blame Revision: D1575098
parent 11ff9f99
......@@ -509,17 +509,23 @@ class SocketAddress {
struct sockaddr_un *addr;
socklen_t len;
/* For debugging only, will be removed */
uint64_t magic;
static constexpr uint64_t kMagic = 0x1234faceb00c;
socklen_t pathLength() const {
return len - offsetof(struct sockaddr_un, sun_path);
}
void init() {
addr = new sockaddr_un;
magic = kMagic;
addr->sun_family = AF_UNIX;
len = 0;
}
void init(const ExternalUnixAddr &other) {
addr = new sockaddr_un;
magic = kMagic;
len = other.len;
memcpy(addr, other.addr, len);
// Fill the rest with 0s, just for safety
......@@ -527,11 +533,14 @@ class SocketAddress {
sizeof(struct sockaddr_un) - len);
}
void copy(const ExternalUnixAddr &other) {
CHECK(magic == kMagic);
len = other.len;
memcpy(addr, other.addr, len);
}
void free() {
CHECK(magic == kMagic);
delete addr;
magic = 0;
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment