Skip to content

Commit

Permalink
Fix various leaks in Foundation (#1834)
Browse files Browse the repository at this point in the history
Thanks to @ehren.
  • Loading branch information
ehren authored and DHowett committed Jan 26, 2017
1 parent 8185374 commit 3a65494
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Frameworks/Foundation/NSLog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@Status Interoperable
*/
void NSLogv(NSString* format, va_list list) {
StrongId<NSString> formattedString = [[NSString alloc] initWithFormat:format arguments:list];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:format arguments:list]);
std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(formattedString);

// This traces to ETW in debug and release modes.
Expand Down
15 changes: 10 additions & 5 deletions Frameworks/Foundation/NSLogging.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
void NSTraceVerbose(const wchar_t* tag, NSString* format, ...) {
va_list list;
va_start(list, format);
StrongId<NSString> formattedString = [[NSString alloc] initWithFormat:format arguments:list];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:format arguments:list]);
std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(formattedString);
TraceVerbose(tag, g_TraceFormat, wideBuffer.c_str());
va_end(list);
Expand All @@ -33,7 +34,8 @@ void NSTraceVerbose(const wchar_t* tag, NSString* format, ...) {
void NSTraceInfo(const wchar_t* tag, NSString* format, ...) {
va_list list;
va_start(list, format);
StrongId<NSString> formattedString = [[NSString alloc] initWithFormat:format arguments:list];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:format arguments:list]);
std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(formattedString);
TraceInfo(tag, g_TraceFormat, wideBuffer.c_str());
va_end(list);
Expand All @@ -42,7 +44,8 @@ void NSTraceInfo(const wchar_t* tag, NSString* format, ...) {
void NSTraceWarning(const wchar_t* tag, NSString* format, ...) {
va_list list;
va_start(list, format);
StrongId<NSString> formattedString = [[NSString alloc] initWithFormat:format arguments:list];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:format arguments:list]);
std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(formattedString);
TraceWarning(tag, g_TraceFormat, wideBuffer.c_str());
va_end(list);
Expand All @@ -51,7 +54,8 @@ void NSTraceWarning(const wchar_t* tag, NSString* format, ...) {
void NSTraceError(const wchar_t* tag, NSString* format, ...) {
va_list list;
va_start(list, format);
StrongId<NSString> formattedString = [[NSString alloc] initWithFormat:format arguments:list];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:format arguments:list]);
std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(formattedString);
TraceError(tag, g_TraceFormat, wideBuffer.c_str());
va_end(list);
Expand All @@ -60,7 +64,8 @@ void NSTraceError(const wchar_t* tag, NSString* format, ...) {
void NSTraceCritical(const wchar_t* tag, NSString* format, ...) {
va_list list;
va_start(list, format);
StrongId<NSString> formattedString = [[NSString alloc] initWithFormat:format arguments:list];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:format arguments:list]);
std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(formattedString);
TraceCritical(tag, g_TraceFormat, wideBuffer.c_str());
va_end(list);
Expand Down
3 changes: 2 additions & 1 deletion Frameworks/Foundation/NSMutableString.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ - (void)appendFormat:(NSString*)formatStr, ... {
va_list reader;
va_start(reader, formatStr);

NSString* endStr = [[NSString alloc] initWithFormat:formatStr arguments:reader];
StrongId<NSString> endStr;
endStr.attach([[NSString alloc] initWithFormat:formatStr arguments:reader]);
va_end(reader);

[self appendString:endStr];
Expand Down
3 changes: 2 additions & 1 deletion Frameworks/Foundation/NSString.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ - (NSString*)stringByAppendingFormat:(NSString*)formatStr, ... {
va_list reader;
va_start(reader, formatStr);

NSString* formattedString = [[NSString alloc] initWithFormat:formatStr arguments:reader];
StrongId<NSString> formattedString;
formattedString.attach([[NSString alloc] initWithFormat:formatStr arguments:reader]);
return [self stringByAppendingString:formattedString];
}

Expand Down
2 changes: 1 addition & 1 deletion Frameworks/Foundation/NSThread.mm
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ + (NSThread*)currentThread {
NSThread* currentThread = [[self class] _threadObjectFromCurrentThread];

if (currentThread == nil) {
currentThread = [NSThread new];
currentThread = [[[NSThread alloc] init] autorelease];
[currentThread _associateWithCurrentThread];
}
return currentThread;
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/Foundation/NSTimer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ - (instancetype)initWithTimeInterval:(double)seconds
_repeats = repeats;
_canFire = YES;
_valid = YES;
_addedToModes = (NSMutableArray*)CFArrayCreateMutable(NULL, 0, NULL);
_addedToModes.attach((NSMutableArray*)CFArrayCreateMutable(NULL, 0, NULL));
_nextFireTime = [NSDate timeIntervalSinceReferenceDate] + _interval;
}

Expand Down

0 comments on commit 3a65494

Please sign in to comment.