Fix malloc/delete asan failure on sctp_lib.cc
Change-Id: Ibf6601b28bd2c8ffb551df825d553fcee2dc42e0
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/network/sctp_lib.cc b/aos/network/sctp_lib.cc
index c3c6e23..0922d6b 100644
--- a/aos/network/sctp_lib.cc
+++ b/aos/network/sctp_lib.cc
@@ -715,8 +715,11 @@
<< "SCTP Authentication key requested, but authentication isn't "
"enabled... Use `sysctl -w net.sctp.auth_enable=1` to enable";
// Set up the key with id `1`.
- std::unique_ptr<sctp_authkey> authkey(
- (sctp_authkey *)malloc(sizeof(sctp_authkey) + auth_key.size()));
+ // NOTE: `sctp_authkey` is a variable-sized struct which is why it needs
+ // to be heap allocated. Regardless, this object doesn't have to persist past
+ // the `setsockopt` call below.
+ std::unique_ptr<sctp_authkey> authkey(static_cast<sctp_authkey *>(
+ ::operator new(sizeof(sctp_authkey) + auth_key.size())));
authkey->sca_keynumber = 1;
authkey->sca_keylength = auth_key.size();