Skip to content

Commit

Permalink
Fix xMalloc usage
Browse files Browse the repository at this point in the history
No need to allocate sizeof(CXXToken) * sizeof(CXXToken) bytes
for a single token structure when 1 * sizeof(CXXToken) bytes is enough.

Same applies to CXXTokenChain.

(also see oracle/opengrok#2364)
  • Loading branch information
edigaryev committed Nov 4, 2018
1 parent ed9b58d commit 6952bef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void cxxTokenForceDestroy(CXXToken * t);

static CXXToken *createToken(void *createArg CTAGS_ATTR_UNUSED)
{
CXXToken *t = xMalloc(sizeof(CXXToken),CXXToken);
CXXToken *t = xMalloc(1, CXXToken);
// we almost always want a string, and since this token
// is being reused..well.. we always want it
t->pszWord = vStringNew();
Expand Down
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_token_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void cxxTokenChainInit(CXXTokenChain * tc)

CXXTokenChain * cxxTokenChainCreate(void)
{
CXXTokenChain * tc = xMalloc(sizeof(CXXTokenChain),CXXTokenChain);
CXXTokenChain * tc = xMalloc(1, CXXTokenChain);
cxxTokenChainInit(tc);
return tc;
}
Expand Down

0 comments on commit 6952bef

Please sign in to comment.