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

[iOS] Incorrect Memory Leak Detection #52

Closed
FredericJacobs opened this issue Jun 14, 2015 · 4 comments
Closed

[iOS] Incorrect Memory Leak Detection #52

FredericJacobs opened this issue Jun 14, 2015 · 4 comments

Comments

@FredericJacobs
Copy link

The following Objective-C code incorrectly results in a error: MEMORY_LEAK memory dynamically allocated to buffer by call to malloc() at line X, column X is not reachable after line X, column X.

void* buffer = malloc(bufferSize);
return [NSData dataWithBytesNoCopy:buffer length:bytesDecrypted freeWhenDone:YES];

The buffer is passed to the returned NSData object and will be deallocated when the NSData instance will be.

@dulmarod
Copy link
Contributor

Hi,
That is a real leak. The documentation of Apple also says that if the NSData object doesn't get created then the method will return nil. In that case the buffer will be leaked.

@FredericJacobs
Copy link
Author

Oh right, thanks.
Got an assertion for that but good point.

@dflems
Copy link

dflems commented Jul 13, 2017

@dulmarod: I still see this as a MEMORY_LEAK after doing a nil-check. Is there a way to silence this? (using infer 0.12.0)

uint8_t *buffer = malloc(length);
...
NSData *data = [NSData dataWithBytesNoCopy:buffer length:length freeWhenDone:YES];
if (!data) {
    free(buffer);
}
return data;

@dulmarod
Copy link
Contributor

dulmarod commented Nov 2, 2017

There isn't a way to silence individual bugs at the moment.

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