Skip to content

Commit

Permalink
sync with tscancode trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
quarkgit committed Nov 30, 2017
1 parent f7acafb commit 43c275d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################

/.svn
/TSC2_samples
/branches
*.db
*.opendb
*.diagsession
/trunk/.vs
/trunk/bin
/trunk/ipch
/trunk/cli/temp
/trunk/lib/temp
*.DS_Store
*.swp
.DS_Store
trunk/tscancode.xcodeproj/project.xcworkspace
trunk/tscancode.xcodeproj/xcuserdata
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ All notable changes of this project will be documented here.
### Added
* Add new check `CS_UnityMessgeSpellWrong`, check typo errors of Unity message functions, e.g. `OnDestroy` is misspelled as `OnDestory`;
* Add new check `lua_VarSpellWrongError` and `lua_KeywordSpellWrongError`, check typo errors of Lua variable and keyword, e.g. `false` is misspelled as `flase`;
* Add new check `unsafeClassCanLeak`, check the code scenario that memory is allocated in the constructor, but isn't released at destructor;

### Fixed
Several known bugs fixed.



1 change: 0 additions & 1 deletion trunk/cfg/cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<subid name="mismatchAllocDealloc" value="1" severity="Warning" rule_name="内存申请和释放不匹配" desc="内存申请和释放的方式不匹配,比如new的内存,用free去释放" />
<subid name="mismatchSize" value="1" severity="Warning" rule_name="内存分配大小错误" desc="alloc的大小和类型的大小不匹配" />
<subid name="virtualDestructor" value="1" severity="Warning" rule_name="虚析构函数使用错误" desc="析构函数没有设置为virtual,如果漏调用可能产生资源泄漏" />
<subid name="unsafeClassCanLeak" value="1" severity="Warning" rule_name="析构函数未释放类成员变量" desc="类成员变量在构造函数或者成员函数中申请了内存,但是在析构函数中没有释放,可能导致内存泄漏" />
</id>
<id name="compute" rule_name="运算错误" value="1">
<subid name="incrementboolean" value="1" severity="Warning" rule_name="bool变量自增" desc="对bool变量使用自增,不符合代码规范,而且可能造成不可预期的错误" />
Expand Down
5 changes: 4 additions & 1 deletion trunk/lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,9 @@ void CheckMemoryLeakInFunction::check()

void CheckMemoryLeakInClass::check()
{
if (!_settings->IsCheckIdOpened(ErrorType::ToString(ErrorType::UserCustom).c_str(), "unsafeClassCanLeak"))
return;

const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

// only check classes and structures
Expand Down Expand Up @@ -2490,7 +2493,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
void CheckMemoryLeakInClass::unsafeClassError(const Token *tok, const std::string &classname, const std::string &varname)
{
//#ifdef TSCANCODE_RULE_OPEN
reportError(tok, Severity::style, ErrorType::MemoryLeak, "unsafeClassCanLeak",
reportError(tok, Severity::style, ErrorType::UserCustom, "unsafeClassCanLeak",
"Class '" + classname + "' is unsafe, as '" + varname + "' is allocated in constructor or functions, but not deallocated in destructor.\n"
"The class '" + classname + "' is unsafe, wrong usage can cause memory/resource leaks for '" + varname + "'. This can for instance be fixed by adding proper cleanup in the destructor.", ErrorLogger::GenWebIdentity(varname));
//#endif
Expand Down

0 comments on commit 43c275d

Please sign in to comment.