Skip to content

Commit

Permalink
Fix a lot of analyzer issues, including quite a few memory leaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Jul 7, 2018
1 parent e562098 commit 8cfe2a1
Show file tree
Hide file tree
Showing 80 changed files with 338 additions and 267 deletions.
2 changes: 1 addition & 1 deletion ThirdParty/PSMTabBarControl/source/PSMTabBarControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ - (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPo
if ([[self delegate] respondsToSelector:@selector(tabView:toolTipForTabViewItem:)]) {
return [[self delegate] tabView:[self tabView] toolTipForTabViewItem:[[self cellForPoint:point cellFrame:nil] representedObject]];
}
return nil;
return @"";
}

#pragma mark -
Expand Down
4 changes: 3 additions & 1 deletion ThirdParty/PSMTabBarControl/source/PSMTabDragAssistant.m
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ - (void)draggedImageEndedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
// This could cause an already correctly positioned window to resize.
[[control tabView] addTabViewItem:[[self draggedCell] representedObject]];

fixOriginBlock();
if (fixOriginBlock) {
fixOriginBlock();
}

[[control window] makeKeyAndOrderFront:nil];

Expand Down
2 changes: 1 addition & 1 deletion ThirdParty/SCEvents/Source/SCEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (void)dealloc
{
[_eventDate release];
_eventDate = nil;
[_eventPath release];
[super dealloc];
}

Expand Down
8 changes: 5 additions & 3 deletions iTerm2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,8 @@
A6057C171883D12E004A60AF /* broken_image.png in Resources */ = {isa = PBXBuildFile; fileRef = A6057C161883D12E004A60AF /* broken_image.png */; };
A605D4B319CF796800D40343 /* NMSSH.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A624232519CF70DF00182C08 /* NMSSH.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
A605D4B419CF796F00D40343 /* NMSSH.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A624232519CF70DF00182C08 /* NMSSH.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
A608F22120F07658008E8009 /* iTermImageMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A62C3B411BD40E7C00B5629D /* iTermImageMark.m */; };
A608F22220F08369008E8009 /* VT100DCSParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A647E39E18C351F400450FA1 /* VT100DCSParser.m */; };
A6099B0518D6B0FD00081FA9 /* iTermWarning.h in Headers */ = {isa = PBXBuildFile; fileRef = A6099B0318D6B0FD00081FA9 /* iTermWarning.h */; };
A60BB37E1EB5149100D76C09 /* iTermCopyModeState.h in Headers */ = {isa = PBXBuildFile; fileRef = A60BB37C1EB5149100D76C09 /* iTermCopyModeState.h */; };
A60BB37F1EB5149100D76C09 /* iTermCopyModeState.m in Sources */ = {isa = PBXBuildFile; fileRef = A60BB37D1EB5149100D76C09 /* iTermCopyModeState.m */; };
Expand Down Expand Up @@ -1430,7 +1432,6 @@
A62C3B3E1BD40DC900B5629D /* iTermCapturedOutputMark.h in Headers */ = {isa = PBXBuildFile; fileRef = A62C3B3C1BD40DC900B5629D /* iTermCapturedOutputMark.h */; };
A62C3B3F1BD40DC900B5629D /* iTermCapturedOutputMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A62C3B3D1BD40DC900B5629D /* iTermCapturedOutputMark.m */; };
A62C3B421BD40E7C00B5629D /* iTermImageMark.h in Headers */ = {isa = PBXBuildFile; fileRef = A62C3B401BD40E7C00B5629D /* iTermImageMark.h */; };
A62C3B431BD40E7C00B5629D /* iTermImageMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A62C3B411BD40E7C00B5629D /* iTermImageMark.m */; };
A62EED9220DF5B2F00943DE3 /* iTermScriptChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = A62EED9020DF5B2F00943DE3 /* iTermScriptChooser.h */; };
A62EED9320DF5B2F00943DE3 /* iTermScriptChooser.m in Sources */ = {isa = PBXBuildFile; fileRef = A62EED9120DF5B2F00943DE3 /* iTermScriptChooser.m */; };
A62EED9620DF602F00943DE3 /* iTermCommandRunner.h in Headers */ = {isa = PBXBuildFile; fileRef = A62EED9420DF602F00943DE3 /* iTermCommandRunner.h */; };
Expand Down Expand Up @@ -2456,7 +2457,6 @@
A6C763BF1B45C52B00E3C992 /* VT100AnsiParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A647E39918C3515900450FA1 /* VT100AnsiParser.m */; };
A6C763C01B45C52B00E3C992 /* VT100ControlParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A647E3AD18C3588800450FA1 /* VT100ControlParser.m */; };
A6C763C11B45C52B00E3C992 /* VT100CSIParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A6A13AB018C33ED300B241ED /* VT100CSIParser.m */; };
A6C763C21B45C52B00E3C992 /* VT100DCSParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A647E39E18C351F400450FA1 /* VT100DCSParser.m */; };
A6C763C31B45C52B00E3C992 /* VT100OtherParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A647E3A318C352B000450FA1 /* VT100OtherParser.m */; };
A6C763C41B45C52B00E3C992 /* VT100Output.m in Sources */ = {isa = PBXBuildFile; fileRef = A6A13AAB18C3347200B241ED /* VT100Output.m */; };
A6C763C51B45C52B00E3C992 /* VT100Parser.m in Sources */ = {isa = PBXBuildFile; fileRef = A6A13AB518C33FC500B241ED /* VT100Parser.m */; };
Expand Down Expand Up @@ -9611,6 +9611,7 @@
A653B6CF20AD3C4100B481F1 /* iTermSessionNameController.m in Sources */,
A64AE5182084128500D02F06 /* NSThread+iTerm.m in Sources */,
A6971F3820DA295A0075CFD4 /* ToolWebView.m in Sources */,
A608F22220F08369008E8009 /* VT100DCSParser.m in Sources */,
530AB7B520A615D900D2AA08 /* iTermPythonArgumentParser.m in Sources */,
A68400BD1FF98101008D3EE2 /* iTermTimestampsRenderer.m in Sources */,
A60C034B20881D6000FE2F1F /* iTermWebSocketCookieJar.m in Sources */,
Expand Down Expand Up @@ -9758,6 +9759,7 @@
53FF982B2093C823008688D7 /* iTermSignatureVerifier.m in Sources */,
535EA4FD20D0EBD300FC81E0 /* iTermSwiftyStringRecognizer.m in Sources */,
A6C1FD521FC2AC9B006B9A69 /* iTermMarginRenderer.m in Sources */,
A608F22120F07658008E8009 /* iTermImageMark.m in Sources */,
A66DABFF20867749006391A3 /* iTermTextViewAccessibilityHelper.m in Sources */,
53C166AB20C21FBB003B03AF /* iTermMigrationHelper.m in Sources */,
A66719611DCE3772000CE608 /* iTermIPV4Address.m in Sources */,
Expand Down Expand Up @@ -9880,6 +9882,7 @@
A62C3B261BCC24AB00B5629D /* iTermCommandHistoryEntryMO.m in Sources */,
A6C763AF1B45C52B00E3C992 /* CoprocessTrigger.m in Sources */,
A6C763C21B45C52B00E3C992 /* VT100DCSParser.m in Sources */,
A6C762DD1B45C52B00E3C992 /* PTYTab.m in Sources */,
A6F3E96F1D60E4F0000E97C4 /* iTermInitialDirectory.m in Sources */,
A6C763CA1B45C52B00E3C992 /* VT100Terminal.m in Sources */,
A6C763541B45C52B00E3C992 /* iTermOpenQuicklyTableCellView.m in Sources */,
Expand Down Expand Up @@ -9942,7 +9945,6 @@
A6C763331B45C52B00E3C992 /* iTermNumberOfSpacesAccessoryViewController.m in Sources */,
A6C7630A1B45C52B00E3C992 /* FindContext.m in Sources */,
A6C762C61B45C52B00E3C992 /* DebugLogging.m in Sources */,
A62C3B431BD40E7C00B5629D /* iTermImageMark.m in Sources */,
A6C763261B45C52B00E3C992 /* PasteEvent.m in Sources */,
A62C3A8A1BCAE03300B5629D /* iTermDirectoryTreeNode.m in Sources */,
A6936B561D2F5CE600521B04 /* iTermAdditionalHotKeyTableCellView.m in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion image_decoder/image_decoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
if (properties) {
CFDictionaryRef const gifProperties = CFDictionaryGetValue(properties,
kCGImagePropertyGIFDictionary);
return (__bridge NSDictionary *)gifProperties;
NSDictionary *result = [(__bridge NSDictionary *)gifProperties copy];
return result;
} else {
return nil;
}
Expand Down
2 changes: 2 additions & 0 deletions sources/Coprocess.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ - (void)dealloc
[outputBuffer_ release];
[_errors release];
[_delegate release];
[_command release];

[super dealloc];
}

Expand Down
1 change: 1 addition & 0 deletions sources/FileTransferManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ - (AXUIElementRef)menuElementNamed:(NSString *)menuName {
AXError error = AXUIElementCopyAttributeValue(appElement,
kAXMenuBarAttribute,
(CFTypeRef *)&menuBar);
CFRelease(appElement);
if (error) {
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions sources/FontSizeEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
@property (nonatomic, assign) NSSize size;

// Returns a text container and layout manager that are ready to measure a capital W.
+ (NSTextContainer *)newTextContainer;
+ (NSLayoutManager *)newLayoutManagerForFont:(NSFont *)aFont textContainer:(NSTextContainer *)textContainer;
+ (NSTextContainer *)textContainer;
+ (NSLayoutManager *)layoutManagerForFont:(NSFont *)aFont textContainer:(NSTextContainer *)textContainer;

+ (instancetype)fontSizeEstimatorForFont:(NSFont *)aFont;

Expand Down
10 changes: 5 additions & 5 deletions sources/FontSizeEstimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (instancetype)initWithSize:(NSSize)s baseline:(double)b {
return self;
}

+ (NSLayoutManager *)newLayoutManagerForFont:(NSFont *)aFont textContainer:(NSTextContainer *)textContainer {
+ (NSLayoutManager *)layoutManagerForFont:(NSFont *)aFont textContainer:(NSTextContainer *)textContainer {
NSString *myString = @"W";

NSTextStorage *textStorage = [[[NSTextStorage alloc] initWithString:myString] autorelease];
Expand All @@ -59,7 +59,7 @@ + (NSLayoutManager *)newLayoutManagerForFont:(NSFont *)aFont textContainer:(NSTe
return layoutManager;
}

+ (NSTextContainer *)newTextContainer {
+ (NSTextContainer *)textContainer {
return [[[NSTextContainer alloc] initWithContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)] autorelease];
}

Expand Down Expand Up @@ -102,9 +102,9 @@ + (id)fontSizeEstimatorForFont:(NSFont *)aFont
size.height = MAX(1, size.height);

if ([iTermAdvancedSettingsModel useExperimentalFontMetrics]) {
NSTextContainer *textContainer = [self newTextContainer];
NSLayoutManager *layoutManager = [self newLayoutManagerForFont:aFont
textContainer:textContainer];
NSTextContainer *textContainer = [self textContainer];
NSLayoutManager *layoutManager = [self layoutManagerForFont:aFont
textContainer:textContainer];
NSRect usedRect = [layoutManager usedRectForTextContainer:textContainer];

fse.size = usedRect.size;
Expand Down
8 changes: 4 additions & 4 deletions sources/Metal/Infrastructure/iTermMetalCellRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ NS_CLASS_AVAILABLE(10_11, NA)
- (void)drawWithFrameData:(iTermMetalFrameData *)frameData
transientState:(__kindof iTermMetalCellRendererTransientState *)transientState;

- (__kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;

@optional
- (void)writeDebugInfoToFolder:(NSURL *)folderURL;
Expand Down Expand Up @@ -82,8 +82,8 @@ NS_CLASS_AVAILABLE(10_11, NA)
piuElementSize:(size_t)piuElementSize
transientStateClass:(Class)transientStateClass NS_DESIGNATED_INITIALIZER;

- (__kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;

@end

Expand Down
4 changes: 2 additions & 2 deletions sources/Metal/Infrastructure/iTermMetalCellRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ - (Class)transientStateClass {
return _transientStateClass;
}

- (__kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer {
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer {
__kindof iTermMetalRendererTransientState *transientState =
[super createTransientStateForConfiguration:configuration commandBuffer:commandBuffer];

Expand Down
14 changes: 7 additions & 7 deletions sources/Metal/Infrastructure/iTermMetalRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ NS_CLASS_AVAILABLE(10_11, NA)
- (void)drawWithFrameData:(iTermMetalFrameData *)frameData
transientState:(__kindof iTermMetalRendererTransientState *)transientState;

- (__kindof iTermMetalRendererTransientState *)createTransientStateForConfiguration:(iTermRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForConfiguration:(iTermRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;

@end

Expand All @@ -58,7 +58,7 @@ NS_CLASS_AVAILABLE(10_11, NA)
- (instancetype)init NS_UNAVAILABLE;

- (void)measureTimeForStat:(int)index ofBlock:(void (^)(void))block;
- (iTermPreciseTimerStats *)stats;
- (nullable iTermPreciseTimerStats *)stats;
- (int)numberOfStats;
- (NSString *)nameForStat:(int)i;

Expand Down Expand Up @@ -128,15 +128,15 @@ NS_CLASS_AVAILABLE(10_11, NA)
fragmentBuffers:(NSDictionary<NSNumber *, id<MTLBuffer>> *)fragmentBuffers
textures:(NSDictionary<NSNumber *, id<MTLTexture>> *)textures;

- (id<MTLTexture>)textureFromImage:(NSImage *)image context:(nullable iTermMetalBufferPoolContext *)context;
- (id<MTLTexture>)textureFromImage:(NSImage *)image context:(nullable iTermMetalBufferPoolContext *)context pool:(nullable iTermTexturePool *)pool;
- (nullable id<MTLTexture>)textureFromImage:(NSImage *)image context:(nullable iTermMetalBufferPoolContext *)context;
- (nullable id<MTLTexture>)textureFromImage:(NSImage *)image context:(nullable iTermMetalBufferPoolContext *)context pool:(nullable iTermTexturePool *)pool;

- (id<MTLRenderPipelineState>)newPipelineWithBlending:(nullable iTermMetalBlending *)blending
vertexFunction:(id<MTLFunction>)vertexFunction
fragmentFunction:(id<MTLFunction>)fragmentFunction;

- (__kindof iTermMetalRendererTransientState *)createTransientStateForConfiguration:(iTermRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForConfiguration:(iTermRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer;

@end

Expand Down
12 changes: 6 additions & 6 deletions sources/Metal/Infrastructure/iTermMetalRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)measureTimeForStat:(int)index ofBlock:(void (^)(void))block {
iTermPreciseTimerStatsMeasureAndRecordTimer(stat);
}

- (iTermPreciseTimerStats *)stats {
- (nullable iTermPreciseTimerStats *)stats {
return NULL;
}

Expand Down Expand Up @@ -250,8 +250,8 @@ - (void)writeFragmentTexture:(id<MTLTexture>)texture index:(NSUInteger)index toF

#pragma mark - Protocol Methods

- (__kindof iTermMetalRendererTransientState * _Nonnull)createTransientStateForConfiguration:(iTermRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer {
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForConfiguration:(iTermRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer {
iTermMetalRendererTransientState *tState = [[self.transientStateClass alloc] initWithConfiguration:configuration];
tState.pipelineState = [self pipelineState];
return tState;
Expand Down Expand Up @@ -344,7 +344,7 @@ - (void)drawWithFrameData:(iTermMetalFrameData *)frameData
return pipeline;
}

- (id<MTLTexture>)textureFromImage:(NSImage *)image context:(nullable iTermMetalBufferPoolContext *)context {
- (nullable id<MTLTexture>)textureFromImage:(NSImage *)image context:(nullable iTermMetalBufferPoolContext *)context {
return [self textureFromImage:image context:context pool:nil];
}

Expand All @@ -368,7 +368,7 @@ - (void)convertWidth:(NSUInteger)width
}
}

- (id<MTLTexture>)textureFromImage:(NSImage *)image context:(iTermMetalBufferPoolContext *)context pool:(iTermTexturePool *)pool {
- (nullable id<MTLTexture>)textureFromImage:(NSImage *)image context:(iTermMetalBufferPoolContext *)context pool:(iTermTexturePool *)pool {
if (!image) {
return nil;
}
Expand Down Expand Up @@ -454,7 +454,7 @@ - (void)drawWithTransientState:(iTermMetalRendererTransientState *)tState
[renderEncoder setRenderPipelineState:tState.pipelineState];

// Add viewport size to vertex buffers
NSDictionary<NSNumber *, id<MTLBuffer>> *vertexBuffers = clientVertexBuffers ?: @{};
NSDictionary<NSNumber *, id<MTLBuffer>> *vertexBuffers;
vertexBuffers =
[clientVertexBuffers dictionaryBySettingObject:[self vertexBufferForViewportSize:tState.configuration.viewportSize]
forKey:@(iTermVertexInputIndexViewportSize)];
Expand Down
11 changes: 9 additions & 2 deletions sources/Metal/Infrastructure/iTermSubpixelModelBuilder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ + (void)drawString:(NSString *)string
glyphs,
numCodes);
ITDebugAssert(ok);

if (!ok) {
return;
}
size_t length = numCodes;

// Note: this is slow. It was faster than core text when I did it rarely, but I'm not sure if
Expand All @@ -152,7 +154,12 @@ + (void)drawString:(NSString *)string
#pragma clang diagnostic pop

// TODO: could use extended srgb on macOS 10.12+
CGContextSetFillColorSpace(ctx, CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
static CGColorSpaceRef srgb;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
srgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
});
CGContextSetFillColorSpace(ctx, srgb);
CGContextSetFillColor(ctx, components);

CGContextSetAllowsFontSubpixelQuantization(ctx, YES);
Expand Down
6 changes: 3 additions & 3 deletions sources/Metal/Renderers/iTermBackgroundColorRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ - (BOOL)rendererDisabled {
return NO;
}

- (__kindof iTermMetalRendererTransientState * _Nonnull)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer {
- (nullable __kindof iTermMetalRendererTransientState *)createTransientStateForCellConfiguration:(iTermCellRenderConfiguration *)configuration
commandBuffer:(id<MTLCommandBuffer>)commandBuffer {
__kindof iTermMetalCellRendererTransientState * _Nonnull transientState =
[_cellRenderer createTransientStateForCellConfiguration:configuration
commandBuffer:commandBuffer];
Expand All @@ -92,7 +92,7 @@ - (void)initializeTransientState:(iTermBackgroundColorRendererTransientState *)t


- (void)drawWithFrameData:(iTermMetalFrameData *)frameData
transientState:(nonnull __kindof iTermMetalRendererTransientState *)transientState {
transientState:(__kindof iTermMetalRendererTransientState *)transientState {
iTermBackgroundColorRendererTransientState *tState = transientState;
[tState enumerateSegments:^(const iTermBackgroundColorPIU *pius, size_t numberOfInstances) {
id<MTLBuffer> piuBuffer = [self->_piuPool requestBufferFromContext:tState.poolContext
Expand Down
Loading

0 comments on commit 8cfe2a1

Please sign in to comment.