lpereira / lwan

Experimental, scalable, high performance HTTP server
https://lwan.ws
GNU General Public License v2.0
5.94k stars 548 forks source link

Memory leaks in lwan #324

Closed ryancaicse closed 2 years ago

ryancaicse commented 2 years ago

The memory block created at Line 125 is leaked in the method parse_listener_prefix. https://github.com/lpereira/lwan/blob/2f34d6ff3fa4cbb4a78e274e09cdf029ebb7c77d/src/lib/lwan.c#L125-L139 https://github.com/lpereira/lwan/blob/2f34d6ff3fa4cbb4a78e274e09cdf029ebb7c77d/src/lib/lwan.c#L400-L404

lpereira commented 2 years ago

Where's the memory leak?

On Sat, Dec 18, 2021, 18:24 ryancaicse @.***> wrote:

The memory block created at Line 125 is leaked in the method parse_listener_prefix.

https://github.com/lpereira/lwan/blob/2f34d6ff3fa4cbb4a78e274e09cdf029ebb7c77d/src/lib/lwan.c#L125-L139

https://github.com/lpereira/lwan/blob/2f34d6ff3fa4cbb4a78e274e09cdf029ebb7c77d/src/lib/lwan.c#L400-L404

— Reply to this email directly, view it on GitHub https://github.com/lpereira/lwan/issues/324, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADVGORGGIPD4O65F2LVL3URU64XANCNFSM5KLKZV5A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

lpereira commented 2 years ago

There's no memory leak in this function. The memory is now owned by the trie, which will call destroy_urlmap() and free the memory. Unless there's a bug in the trie data structure, of course.

Are you using some static analysis tool to find these? Because if you are, these tools can be wrong most of the time, especially when "ownership" is passed around like this and function pointers are called to free the memory.

On Sat, Dec 18, 2021, 18:40 L. Pereira @.***> wrote:

Where's the memory leak?

On Sat, Dec 18, 2021, 18:24 ryancaicse @.***> wrote:

The memory block created at Line 125 is leaked in the method parse_listener_prefix.

https://github.com/lpereira/lwan/blob/2f34d6ff3fa4cbb4a78e274e09cdf029ebb7c77d/src/lib/lwan.c#L125-L139

https://github.com/lpereira/lwan/blob/2f34d6ff3fa4cbb4a78e274e09cdf029ebb7c77d/src/lib/lwan.c#L400-L404

— Reply to this email directly, view it on GitHub https://github.com/lpereira/lwan/issues/324, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADVGORGGIPD4O65F2LVL3URU64XANCNFSM5KLKZV5A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

ryancaicse commented 2 years ago

@lpereira Sorry, when I take a close look, it seems it's wrong.