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 leak #9

Open
SiriusBrent opened this issue Jun 21, 2017 · 0 comments
Open

Memory leak #9

SiriusBrent opened this issue Jun 21, 2017 · 0 comments

Comments

@SiriusBrent
Copy link

There's a memory leak in Markdown.swift at line 47:

var dest = [UnsafeMutablePointer<Int8>?](repeating: UnsafeMutablePointer<Int8>.allocate(capacity: 1), count: 1)

This line is allocating space for a pointer to be returned, but in doing so is also allocating an actual pointer to one byte of memory. When fun is called to process data and return a result, the allocated pointer is overwritten and the one-byte allocation (16 actual bytes) is lost.

Since all you need is space for a pointer here, and since the array is an array-of-optionals, you can just replace that line with this:

var dest: [UnsafeMutablePointer<Int8>?] = [nil]

No allocation, so no leak.

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

1 participant