Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Don't strdup the inputFileName when storing a tag to the corkQueue #3682

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,14 @@ static tagEntryInfo *newNilTagEntry (unsigned int corkFlags)
x->corkIndex = CORK_NIL;
x->symtab = RB_ROOT;
x->slot.kindIndex = KIND_FILE_INDEX;
x->slot.inputFileName = getInputFileName ();
x->slot.inputFileName = eStrdup (x->slot.inputFileName);
return &(x->slot);
}

static tagEntryInfoX *copyTagEntry (const tagEntryInfo *const tag,
unsigned int corkFlags)
const char *shareInputFileName,
unsigned int corkFlags)
{
tagEntryInfoX *x = xMalloc (1, tagEntryInfoX);
x->symtab = RB_ROOT;
Expand All @@ -1075,7 +1078,17 @@ static tagEntryInfoX *copyTagEntry (const tagEntryInfo *const tag,
if (slot->pattern)
slot->pattern = eStrdup (slot->pattern);

slot->inputFileName = eStrdup (slot->inputFileName);
if (slot->inputFileName == getInputFileName ())
{
slot->inputFileName = shareInputFileName;
slot->isInputFileNameShared = 1;
}
else
{
slot->inputFileName = eStrdup (slot->inputFileName);
slot->isInputFileNameShared = 0;
}

slot->name = eStrdup (slot->name);
if (slot->extensionFields.access)
slot->extensionFields.access = eStrdup (slot->extensionFields.access);
Expand Down Expand Up @@ -1146,11 +1159,17 @@ static void deleteTagEnry (void *data)
tagEntryInfo *slot = data;

if (slot->kindIndex == KIND_FILE_INDEX)
{
eFree ((char *)slot->inputFileName);
goto out;
}

if (slot->pattern)
eFree ((char *)slot->pattern);
eFree ((char *)slot->inputFileName);

if (!slot->isInputFileNameShared)
eFree ((char *)slot->inputFileName);

eFree ((char *)slot->name);

if (slot->extensionFields.access)
Expand Down Expand Up @@ -1515,7 +1534,8 @@ static int queueTagEntry (const tagEntryInfo *const tag)
static bool warned;

int corkIndex;
tagEntryInfoX * entry = copyTagEntry (tag,
tagEntryInfo * nil = ptrArrayItem (TagFile.corkQueue, 0);
tagEntryInfoX * entry = copyTagEntry (tag, nil->inputFileName,
TagFile.corkFlags);

if (ptrArrayCount (TagFile.corkQueue) == (size_t)INT_MAX)
Expand Down
12 changes: 11 additions & 1 deletion main/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@ struct sTagEntryInfo {
unsigned int isPseudoTag:1; /* Used only in xref output.
If a tag is a pseudo, set this. */
unsigned int inCorkQueue:1;
unsigned int isInputFileNameShared: 1; /* shares the value for inputFileName.
* Set in the cork queue; don't touch this.*/

unsigned long lineNumber; /* line number of tag */
const char* pattern; /* pattern for locating input line
* (may be NULL if not present) *//* */
unsigned int boundaryInfo; /* info about nested input stream */
MIOPos filePosition; /* file position of line containing tag */
langType langType; /* language of input file */
const char *inputFileName; /* name of input file */
const char *inputFileName; /* name of input file.
You cannot modify the contents of buffer pointed
by this member of the tagEntryInfo returned from
getEntryInCorkQueue(). The buffer may be shared
between tag entries in the cork queue.
Further more, modifying this member of the
tagEntryInfo returned from getEntryInCorkQueue()
may cause a memory leak. */
const char *name; /* name of the tag */
int kindIndex; /* kind descriptor */
uint8_t extra[ ((XTAG_COUNT) / 8) + 1 ];
Expand Down