从终端进行 iPhone 静态代码分析未能找到丢失的 ivar 版本
我有一个在终端中运行的脚本,该脚本在我的 iPhone 应用程序上运行扫描构建代码分析器来检查问题。我只是偶然注意到,至少有一个实例没有找到未在 dealloc 方法中释放的 IBOutlet ivar。
以下是我从终端运行的命令的内容:
#!/bin/sh
cd /Developer/svn/MyCompany/iPhone/MyApplication
scan-build -analyzer-check-dead-stores -analyzer-check-llvm-conventions -analyzer-check-objc-mem -analyzer-check-objc-methodsigs -analyzer-check-objc-missing-dealloc -analyzer-check-objc-unused-ivars -analyzer-check-security-syntactic --experimental-checks -k -V -o scan-reports xcodebuild -configuration Debug -sdk iphonesimulator4.2 clean build
我已更新到 checker 的最新版本,因此不可能有较新版本的 checker。以下是我的类的 .h 文件的相关部分:
@interface LoginWizardUsernameViewController : UIViewController <UITextFieldDelegate, GetUserExistsDidFinish> {
IBOutlet UITextField *username;
IBOutlet UIActivityIndicatorView *activityIndicatorView;
}
@property (nonatomic, retain) UITextField *username;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicatorView;
以下是 .m 文件的相关部分:
// lots o' code omitted here
@implementation LoginWizardUsernameViewController
@synthesize username;
@synthesize activityIndicatorView;
- (void)dealloc
{
[super dealloc];
}
正如您所看到的,这两个 IBOutlet 项没有被释放,但即使它们被列为保留在属性定义,检查器由于某种原因没有看到这一点。奇怪的是,我可以转到其他类的 .m 文件,并在 dealloc 方法中注释掉某个版本,并且 scan-build 在问题扫描结束时愉快地提醒我。我只是无法弄清楚这种特殊情况有什么不同。
I have a script that I run in terminal that runs the scan-build code analyzer on my iPhone applications to check for issues. I just noticed quite by accident that there is at least one instance where it is not finding an IBOutlet ivar that is not being released in the dealloc method.
Here is the contents of the command I run from the Terminal:
#!/bin/sh
cd /Developer/svn/MyCompany/iPhone/MyApplication
scan-build -analyzer-check-dead-stores -analyzer-check-llvm-conventions -analyzer-check-objc-mem -analyzer-check-objc-methodsigs -analyzer-check-objc-missing-dealloc -analyzer-check-objc-unused-ivars -analyzer-check-security-syntactic --experimental-checks -k -V -o scan-reports xcodebuild -configuration Debug -sdk iphonesimulator4.2 clean build
I have updated to the very latest version of checker, so it can't be that there is a newer version of checker. Here are the pertinent parts of the .h file for my class:
@interface LoginWizardUsernameViewController : UIViewController <UITextFieldDelegate, GetUserExistsDidFinish> {
IBOutlet UITextField *username;
IBOutlet UIActivityIndicatorView *activityIndicatorView;
}
@property (nonatomic, retain) UITextField *username;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicatorView;
And here are the pertinent parts of the .m file:
// lots o' code omitted here
@implementation LoginWizardUsernameViewController
@synthesize username;
@synthesize activityIndicatorView;
- (void)dealloc
{
[super dealloc];
}
As you can see, there is no release of the two IBOutlet items, but even though they are listed as retained in the property definition, checker is not seeing this for some reason. The strange thing is that I can go to the .m file of other classes and comment out a release in the dealloc method, and scan-build happily alerts me at the end of the scan of the problem. I just cannot figure out what is different about this particular situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Clang 静态分析器中的一个 bug,由尝试修复不同的问题。
基于源代码,Clang静态分析器将跳过
-dealloc 检查任何包含 only 非指针 ivars 或
IBOutlet
ivars 的类:我怀疑如果您只需向类添加非 IBOutlet 属性,它就能正常工作。
This is a bug in the Clang static analyzer, caused by an attempt to fix a different issue.
Based on the source code, the Clang static analyzer will skip
-dealloc
checking for any class which contains only non-pointer ivars orIBOutlet
ivars:I suspect that it will work properly if you simply add a non-IBOutlet property to your class.