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

Memory Leaks on iOS TOMLTable.convert(to:options:) #26

Open
codingiran opened this issue Jan 9, 2024 · 4 comments
Open

Memory Leaks on iOS TOMLTable.convert(to:options:) #26

codingiran opened this issue Jan 9, 2024 · 4 comments

Comments

@codingiran
Copy link

codingiran commented Jan 9, 2024

My Code is quit simple:

// a toml string
var tomlString = '''
port = 6789
socks_port = 7890
allow_lan = false
bind_address = '*'
log_level = 'debug'
ipv6 = false
tun_fd = 0
'''
// `NetspeedConfig` is a Swift Struct define in my app
var config = try TOMLDecoder().decode(NetspeedConfig.self, from: tomlString)

// set property etc.
config.tun_fd = 10
...

// convert to toml string
tomlString = try TOMLEncoder().encode(config)

// create a TOMLKit table
let table = try TOMLTable(string: tomlString)

// convert to strings
let output_toml = table.convert(to: .toml)
let output_json = table.convert(to: .json)
let output_yaml = table.convert(to: .yaml)
iShot_2024-01-09_16 46 58

Xcode Instruments catch this memory leak, please download it and check in Xcode
https://github.com/codingiran/TOMLKit/blob/main/MemoryLeaks/TOMlKit%20Memory%20Leaks.trace.zip

@codingiran codingiran changed the title Memory Leaks on iOS on TOMLTable.convert(to:options:) Memory Leaks on iOS TOMLTable.convert(to:options:) Jan 9, 2024
@nikitabobko
Copy link

nikitabobko commented Jan 3, 2025

The library is full of memory leaks. Basically, almost every returned value from cpp to Swift is returned via malloc or cpp new and never freed...

@nikitabobko
Copy link

There a few probably trivial memory leak fixes?

But the one this issue is about inside TOMLTable.init / tableCreateFromString is slightly more complicated. A simple TOMLTable.deinit cannot be slapped in, because the ownership for tablePointer: OpaquePointer are not immediately trivial to me. The pointer can travel from TOMLTable to TOMLTable.

@xiaowei-dreame
Copy link

This makes me worried to use😂

@codingiran
Copy link
Author

This makes me worried to use😂

@nikitabobko did fix memory leak, you can try his fork version

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

3 participants