Module: kamailio
Branch: 5.2
Commit: 891bd927f3e519bb9fb2f23a65f21f82f2f7e0af
URL:
https://github.com/kamailio/kamailio/commit/891bd927f3e519bb9fb2f23a65f21f8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-08-15T12:43:58+02:00
core: forward - clone outbound buffer for SREV_NET_DATA_OUT event
- this event can execute a series of callbacks, leading to leak if only
the core function does pkg free
- GH #2027
(cherry picked from commit 98249e2cc97e818cf7ad492132ecfea2ce13a78b)
---
Modified: src/core/forward.h
---
Diff:
https://github.com/kamailio/kamailio/commit/891bd927f3e519bb9fb2f23a65f21f8…
Patch:
https://github.com/kamailio/kamailio/commit/891bd927f3e519bb9fb2f23a65f21f8…
---
diff --git a/src/core/forward.h b/src/core/forward.h
index d039900aac..a629748686 100644
--- a/src/core/forward.h
+++ b/src/core/forward.h
@@ -136,9 +136,18 @@ static inline int msg_send_buffer(struct dest_info* dst, char* buf,
int len,
outb.s = buf;
outb.len = len;
if(!(flags&1)) {
- evp.data = (void*)&outb;
- evp.dst = dst;
- sr_event_exec(SREV_NET_DATA_OUT, &evp);
+ if(sr_event_enabled(SREV_NET_DATA_OUT)) {
+ outb.s = (char*)pkg_malloc(len + 1);
+ if(outb.s==NULL) {
+ LM_ERR("failed to clone outgoing buffer\n");
+ return -1;
+ }
+ memcpy(outb.s, buf, len);
+ outb.s[len] = '\0';
+ evp.data = (void*)&outb;
+ evp.dst = dst;
+ sr_event_exec(SREV_NET_DATA_OUT, &evp);
+ }
}
if(outb.s==NULL) {