Navigation Menu

Skip to content

Commit

Permalink
Fixed a number of issues (resource leaks, uninitialized members, etc)…
Browse files Browse the repository at this point in the history
… found by coverity
  • Loading branch information
Dimitri van Heesch committed Aug 31, 2014
1 parent b59edd2 commit 4188783
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion qtools/qgstring.cpp
Expand Up @@ -209,7 +209,7 @@ QGString &QGString::operator+=( const QGString &s )
assert(memSize>=len1+len2+1);
char *newData = memSize!=m_memSize ? (char*)realloc( m_data, memSize ) : m_data;
m_memSize = memSize;
if (m_data)
if (newData)
{
m_data = newData;
memcpy( m_data + len1, s, len2 + 1 );
Expand Down
1 change: 1 addition & 0 deletions qtools/qthread.cpp
Expand Up @@ -52,6 +52,7 @@ QThread::~QThread()
QMutexLocker locker(&d->mutex);
if (d->running && !d->finished)
qWarning("QThread: Destroyed while thread is still running");
delete d;
}

bool QThread::isFinished() const
Expand Down
3 changes: 2 additions & 1 deletion src/docparser.cpp
Expand Up @@ -76,7 +76,8 @@ static const char *sectionLevelToName[] =
"section",
"subsection",
"subsubsection",
"paragraph"
"paragraph",
"subparagraph"
};

//---------------------------------------------------------------------------
Expand Down
53 changes: 26 additions & 27 deletions src/doxygen.cpp
Expand Up @@ -2077,18 +2077,15 @@ static void findUsingDeclarations(EntryNav *rootNav)
usingCd->name().data(),nd?nd->name().data():fd->name().data());
}

if (usingCd) // add the class to the correct scope
if (nd)
{
if (nd)
{
//printf("Inside namespace %s\n",nd->name().data());
nd->addUsingDeclaration(usingCd);
}
else if (fd)
{
//printf("Inside file %s\n",fd->name().data());
fd->addUsingDeclaration(usingCd);
}
//printf("Inside namespace %s\n",nd->name().data());
nd->addUsingDeclaration(usingCd);
}
else if (fd)
{
//printf("Inside file %s\n",fd->name().data());
fd->addUsingDeclaration(usingCd);
}
}

Expand Down Expand Up @@ -4107,8 +4104,12 @@ static QDict<int> *getTemplateArgumentsInName(ArgumentList *templateArguments,co
*/
static ClassDef *findClassWithinClassContext(Definition *context,ClassDef *cd,const QCString &name)
{
FileDef *fd=cd->getFileDef();
ClassDef *result=0;
if (cd==0)
{
return result;
}
FileDef *fd=cd->getFileDef();
if (context && cd!=context)
{
result = getResolvedClass(context,0,name,0,0,TRUE,TRUE);
Expand All @@ -4121,7 +4122,7 @@ static ClassDef *findClassWithinClassContext(Definition *context,ClassDef *cd,co
{
result = getClass(name);
}
if (result==0 && cd &&
if (result==0 &&
(cd->getLanguage()==SrcLangExt_CSharp || cd->getLanguage()==SrcLangExt_Java) &&
name.find('<')!=-1)
{
Expand Down Expand Up @@ -4243,13 +4244,10 @@ static void findUsedClassesForClass(EntryNav *rootNav,
usedCd->setLanguage(masterCd->getLanguage());
Doxygen::hiddenClasses->append(usedName,usedCd);
}
if (usedCd)
{
if (isArtificial) usedCd->setArtificial(TRUE);
Debug::print(Debug::Classes,0," Adding used class `%s' (1)\n", usedCd->name().data());
instanceCd->addUsedClass(usedCd,md->name(),md->protection());
usedCd->addUsedByClass(instanceCd,md->name(),md->protection());
}
if (isArtificial) usedCd->setArtificial(TRUE);
Debug::print(Debug::Classes,0," Adding used class `%s' (1)\n", usedCd->name().data());
instanceCd->addUsedClass(usedCd,md->name(),md->protection());
usedCd->addUsedByClass(instanceCd,md->name(),md->protection());
}
}
}
Expand Down Expand Up @@ -6585,7 +6583,7 @@ static void findMember(EntryNav *rootNav,
funcType,funcName,funcArgs,exceptions,
root->protection,root->virt,
root->stat && !isMemberOf,
isMemberOf ? Foreign : isRelated ? Related : Member,
isMemberOf ? Foreign : Related,
mtype,
(root->tArgLists ? root->tArgLists->getLast() : 0),
funcArgs.isEmpty() ? 0 : root->argList);
Expand Down Expand Up @@ -8062,13 +8060,14 @@ static void generateClassList(ClassSDict &classSDict)
ClassDef *cd=cli.current();

//printf("cd=%s getOuterScope=%p global=%p\n",cd->name().data(),cd->getOuterScope(),Doxygen::globalScope);
if ((cd->getOuterScope()==0 || // <-- should not happen, but can if we read an old tag file
if (cd &&
(cd->getOuterScope()==0 || // <-- should not happen, but can if we read an old tag file
cd->getOuterScope()==Doxygen::globalScope // only look at global classes
) && !cd->isHidden() && !cd->isEmbeddedInOuterScope()
)
)
{
// skip external references, anonymous compounds and
// template instances
// skip external references, anonymous compounds and
// template instances
if ( cd->isLinkableInProject() && cd->templateMaster()==0)
{
msg("Generating docs for compound %s...\n",cd->name().data());
Expand Down Expand Up @@ -9003,9 +9002,9 @@ static void generateNamespaceDocs()

// for each class in the namespace...
ClassSDict::Iterator cli(*nd->getClassSDict());
for ( ; cli.current() ; ++cli )
ClassDef *cd;
for ( ; (cd=cli.current()) ; ++cli )
{
ClassDef *cd=cli.current();
if ( ( cd->isLinkableInProject() &&
cd->templateMaster()==0
) // skip external references, anonymous compounds and
Expand Down
1 change: 1 addition & 0 deletions src/htmlhelp.cpp
Expand Up @@ -281,6 +281,7 @@ HtmlHelp::HtmlHelp() : indexFileDict(1009)
HtmlHelp::~HtmlHelp()
{
if (m_fromUtf8!=(void *)(-1)) portable_iconv_close(m_fromUtf8);
delete index;
}
#if 0
/*! return a reference to the one and only instance of this class.
Expand Down
2 changes: 1 addition & 1 deletion src/index.cpp
Expand Up @@ -1640,7 +1640,7 @@ static void writeAnnotatedClassList(OutputList &ol)

static QCString letterToLabel(uint startLetter)
{
char s[10];
char s[11]; // max 0x12345678 + '\0'
if (startLetter>0x20 && startLetter<=0x7f) // printable ASCII character
{
s[0]=(char)startLetter;
Expand Down
1 change: 1 addition & 0 deletions src/msc.cpp
Expand Up @@ -74,6 +74,7 @@ static bool convertMapFile(FTextStream &t,const char *mapName,const QCString rel
t << externalRef(relPath,df->ref(),TRUE);
if (!df->file().isEmpty()) t << df->file() << Doxygen::htmlFileExtension;
if (!df->anchor().isEmpty()) t << "#" << df->anchor();
delete df;
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/pre.l
Expand Up @@ -207,6 +207,7 @@ class DefineManager
if (dpf==0)
{
dpf = new DefinesPerFile;
m_fileMap.insert(fileName,dpf);
}
dpf->addDefine(def);
}
Expand All @@ -223,6 +224,7 @@ class DefineManager
if (dpf==0)
{
dpf = new DefinesPerFile;
m_fileMap.insert(fromFileName,dpf);
}
dpf->addInclude(toFileName);
}
Expand Down Expand Up @@ -2283,6 +2285,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
}
<DefName>{ID}/("\\\n")*"(" { // define with argument
//printf("Define() `%s'\n",yytext);
delete g_argDict;
g_argDict = new QDict<int>(31);
g_argDict->setAutoDelete(TRUE);
g_defArgs = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/template.cpp
Expand Up @@ -1165,7 +1165,7 @@ class FilterAlphaIndex
}
static QCString keyToLabel(uint startLetter)
{
char s[10];
char s[11]; // 0x12345678 + '\0'
if (startLetter>0x20 && startLetter<=0x7f) // printable ASCII character
{
s[0]=tolower((char)startLetter);
Expand Down Expand Up @@ -2403,7 +2403,7 @@ TemplateVariant TemplateContextImpl::get(const QCString &name) const
warn(m_templateName,m_line,"using . on an object '%s' is not an struct or list",objName.data());
return TemplateVariant();
}
} while (i!=-1);
}
return v;
}
}
Expand Down Expand Up @@ -2860,7 +2860,7 @@ class TemplateNodeRange : public TemplateNodeCreator<TemplateNodeRange>
{
public:
TemplateNodeRange(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeRange>(parser,parent,line)
: TemplateNodeCreator<TemplateNodeRange>(parser,parent,line), m_down(FALSE)
{
TRACE(("{TemplateNodeRange(%s)\n",data.data()));
QCString start,end;
Expand Down Expand Up @@ -3030,7 +3030,7 @@ class TemplateNodeFor : public TemplateNodeCreator<TemplateNodeFor>
{
public:
TemplateNodeFor(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeFor>(parser,parent,line)
: TemplateNodeCreator<TemplateNodeFor>(parser,parent,line), m_reversed(FALSE)
{
TRACE(("{TemplateNodeFor(%s)\n",data.data()));
QCString exprStr;
Expand Down Expand Up @@ -3438,7 +3438,7 @@ class TemplateNodeCreate : public TemplateNodeCreator<TemplateNodeCreate>
{
public:
TemplateNodeCreate(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeCreate>(parser,parent,line)
: TemplateNodeCreator<TemplateNodeCreate>(parser,parent,line), m_templateExpr(0), m_fileExpr(0)
{
TRACE(("TemplateNodeCreate(%s)\n",data.data()));
ExpressionParser ep(parser,line);
Expand Down Expand Up @@ -4013,7 +4013,7 @@ class TemplateNodeMarkers : public TemplateNodeCreator<TemplateNodeMarkers>
{
public:
TemplateNodeMarkers(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeMarkers>(parser,parent,line)
: TemplateNodeCreator<TemplateNodeMarkers>(parser,parent,line), m_listExpr(0), m_patternExpr(0)
{
TRACE(("{TemplateNodeMarkers(%s)\n",data.data()));
int i = data.find(" in ");
Expand Down

0 comments on commit 4188783

Please sign in to comment.