Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any known memory leak in nta? #1

Open
tenge-amzn opened this issue Jan 13, 2019 · 2 comments
Open

Any known memory leak in nta? #1

tenge-amzn opened this issue Jan 13, 2019 · 2 comments

Comments

@tenge-amzn
Copy link

Hi,
It's great to find out someone is actively working on this old lib.
I recently discovered memory leak when calling the sofia lib, but haven't find out exact location.

I was browsing the code in nta, in incoming_reclaim, it seems the irq->irq_rq(the request headers which is a linked list) isn't freed, but I'm not sure if I missed somewhere else.

@davehorton
Copy link
Owner

Do you have a simple scenario that illustrates the memory leak? If so, that would be helpful to me in trying to troubleshoot. I am not aware of any leaks in sofia-sip, but my investigation has not been exhaustive so I welcome any detailed bug reports.

@tenge-amzn
Copy link
Author

I was simply using valgrind to detect the memory leaks. It seems all the definite lost are from sofia lib.
But on my second thought, it could be the code that using the lib in a wrong way.

I read about the docs of sofia lib, and all the memory allocation with the lib is home-based.
So what life cycle of the home object would be appropriated? Per SIP transaction? Currently home object is initialized at service starting up and deinit when service down.

==25605== 6,788 (2,096 direct, 4,692 indirect) bytes in 1 blocks are definitely lost in loss record 1,501 of 1,539
==25605== at 0x4C2A975: calloc (vg_replace_malloc.c:711)
==25605== by 0x7357C31: su_hash_alloc (su_alloc.c:390)
==25605== by 0x7357D54: sub_alloc (su_alloc.c:444)
==25605== by 0x7358858: su_alloc (su_alloc.c:784)
==25605== by 0x72B1677: msg_header_alloc (msg_parser.c:2312)
==25605== by 0x72ABB41: msg_header_copy_one_as (msg_header_copy.c:115)
==25605== by 0x72ABC9F: msg_header_copy_as (msg_header_copy.c:161)
==25605== by 0x72C421B: sip_call_id_copy (sip_protos.h:2422)
==25605== by 0x72D6BB4: incoming_create (nta.c:5316)
==25605== by 0x72D51EC: leg_recv (nta.c:4750)
==25605== by 0x72CE9E1: agent_recv_request (nta.c:2972)
==25605== by 0x72CD4A0: agent_recv_message (nta.c:2753)
==25605==
==25605== 7,058 (231 direct, 6,827 indirect) bytes in 1 blocks are definitely lost in loss record 1,502 of 1,539
==25605== at 0x4C28BE3: malloc (vg_replace_malloc.c:299)
==25605== by 0x7357FE2: sub_alloc (su_alloc.c:490)
==25605== by 0x7358858: su_alloc (su_alloc.c:784)
==25605== by 0x72B1677: msg_header_alloc (msg_parser.c:2312)
==25605== by 0x72AEE18: header_parse (msg_parser.c:1114)
==25605== by 0x72AECAC: extract_header (msg_parser.c:1071)
==25605== by 0x72AE948: extract_next (msg_parser.c:1001)
==25605== by 0x72AE46E: msg_extract (msg_parser.c:903)
==25605== by 0x7378B3D: tport_parse (tport.c:2901)
==25605== by 0x7378A7E: tport_recv_event (tport.c:2874)
==25605== by 0x73786EF: tport_base_wakeup (tport.c:2775)
==25605== by 0x7378674: tport_wakeup (tport.c:2761)
==25605==
==25605== 7,059 (152 direct, 6,907 indirect) bytes in 1 blocks are definitely lost in loss record 1,503 of 1,539
==25605== at 0x4C28BE3: malloc (vg_replace_malloc.c:299)
==25605== by 0x7357FE2: sub_alloc (su_alloc.c:490)
==25605== by 0x7358858: su_alloc (su_alloc.c:784)
==25605== by 0x72B1677: msg_header_alloc (msg_parser.c:2312)
==25605== by 0x72ABB41: msg_header_copy_one_as (msg_header_copy.c:115)
==25605== by 0x72ABC9F: msg_header_copy_as (msg_header_copy.c:161)
==25605== by 0x72C3E7E: sip_request_copy (sip_protos.h:280)
==25605== by 0x72D6B45: incoming_create (nta.c:5313)
==25605== by 0x72D51EC: leg_recv (nta.c:4750)
==25605== by 0x72CE9E1: agent_recv_request (nta.c:2972)
==25605== by 0x72CD4A0: agent_recv_message (nta.c:2753)
==25605== by 0x73793AE: tport_base_deliver (tport.c:3026)

richnew10 added a commit to richnew10/sofia-sip that referenced this issue Apr 17, 2019
This commit has the following changes to `sip_method_d` in `sip_parser.c`, plus supporting files:

* Take the size of the input string as an argument, a pattern established by other functions.
* Use the minimum of this and the lengths of each method string, with `null` terminator subtracted, to bound `strncmp`.
* Bounds-check `n` prior to use throughout the rest of `sip_method_d`, incrementing no further than one character off the end of the input string. Without these bounds checks it was possible for malformed input to overflow the buffer; for example:

```
=================================================================
==77681==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60700000236b at pc 0x563cc24ff234 bp 0x7ffe52888f40 sp 0x7ffe52888f30
READ of size 1 at 0x60700000236b thread T0
    #0 0x563cc24ff233 in sip_method_d drachtio-server/deps/sofia-sip/libsofia-sip-ua/sip/sip_parser.c:416
    davehorton#1 0x563cc24f4c6b in sip_cseq_d drachtio-server/deps/sofia-sip/libsofia-sip-ua/sip/sip_basic.c:1212
    davehorton#2 0x563cc247c025 in header_parse drachtio-server/deps/sofia-sip/libsofia-sip-ua/msg/msg_parser.c:1132
    davehorton#3 0x563cc247b9c4 in extract_header drachtio-server/deps/sofia-sip/libsofia-sip-ua/msg/msg_parser.c:1071
    davehorton#4 0x563cc247afb5 in extract_next drachtio-server/deps/sofia-sip/libsofia-sip-ua/msg/msg_parser.c:1001

0x60700000236b is located 1 bytes to the right of 74-byte region [0x607000002320,0x60700000236a)
allocated by thread T0 here:
    #0 0x7f1faa4dcb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
    davehorton#1 0x563cc252f2da in sub_alloc drachtio-server/deps/sofia-sip/libsofia-sip-ua/su/su_alloc.c:541
    davehorton#2 0x563cc252fce8 in su_alloc drachtio-server/deps/sofia-sip/libsofia-sip-ua/su/su_alloc.c:960
    davehorton#3 0x563cc248257d in msg_header_alloc drachtio-server/deps/sofia-sip/libsofia-sip-ua/msg/msg_parser.c:231
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants