Skip to content
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
34 changes: 7 additions & 27 deletions source/dcautil/dca.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ static bool firstreport_after_bootup = false; // the rotated logs check should r
// Define a struct to hold the file descriptor and size
typedef struct
{
int fd;
off_t cf_map_size;
off_t rf_map_size;
off_t cf_file_size;
Expand Down Expand Up @@ -966,11 +965,6 @@ static void freeFileDescriptor(FileDescriptor* fileDescriptor)
}
fileDescriptor->cfaddr = NULL;
fileDescriptor->rfaddr = NULL;
if(fileDescriptor->fd != -1)
{
close(fileDescriptor->fd);
fileDescriptor->fd = -1;
}
free(fileDescriptor);
}
}
Expand Down Expand Up @@ -1119,7 +1113,6 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s

T2Debug("Log file got rotated. Ignoring invalid mapping\n");
close(tmp_fd);
close(fd);
if(rd != -1)
{
close(rd);
Expand Down Expand Up @@ -1147,13 +1140,11 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s
{
T2Debug("Log file got rotated. Ignoring invalid mapping\n");
close(tmp_fd);
close(fd);
return NULL;
}
addrrf = NULL;
}
close(tmp_fd);
close(fd);

if (addrcf == MAP_FAILED)
{
Expand Down Expand Up @@ -1196,7 +1187,6 @@ static FileDescriptor* getFileDeltaInMemMapAndSearch(const int fd, const off_t s
fileDescriptor->rfaddr = NULL;
}
fileDescriptor->cfaddr = addrcf;
fileDescriptor->fd = fd;
fileDescriptor->cf_map_size = main_fsize;
fileDescriptor->cf_file_size = sb.st_size;
if(fileDescriptor->rfaddr != NULL)
Expand Down Expand Up @@ -1283,12 +1273,6 @@ static int parseMarkerListOptimized(GrepSeekProfile *gsProfile, Vector * ip_vMar
prevfile = NULL;
}

if (fd != -1)
{
close(fd);
fd = -1;
}

if (fileDescriptor != NULL)
{
freeFileDescriptor(fileDescriptor);
Expand All @@ -1306,14 +1290,16 @@ static int parseMarkerListOptimized(GrepSeekProfile *gsProfile, Vector * ip_vMar
}

fileDescriptor = getFileDeltaInMemMapAndSearch(fd, seek_value, logPath, log_file_for_this_iteration, check_rotated_logs);

if (fd != -1)
{
close(fd);
fd = -1;
}

if (fileDescriptor == NULL)
{
T2Error("Failed to get file descriptor for %s\n", log_file_for_this_iteration);
if (fd != -1)
{
close(fd);
fd = -1;
}
continue;
}
}
Expand All @@ -1338,12 +1324,6 @@ static int parseMarkerListOptimized(GrepSeekProfile *gsProfile, Vector * ip_vMar
prevfile = NULL;
}

if (fd != -1)
{
close(fd);
fd = -1;
}

if (fileDescriptor != NULL)
{
freeFileDescriptor(fileDescriptor);
Expand Down
16 changes: 4 additions & 12 deletions source/test/dcautils/dcautilTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,7 @@ TEST_F(dcaTestFixture, getDCAResultsInVector_1)
.Times(1)
.WillOnce(Return(0));
EXPECT_CALL(*g_fileIOMock, close(_))
.Times(4)
.WillOnce(Return(0))
.WillOnce(Return(0))
.Times(2)
.WillOnce(Return(0))
.WillOnce(Return(0));

Expand Down Expand Up @@ -1275,9 +1273,7 @@ TEST_F(dcaTestFixture, getDCAResultsInVector_2)
.Times(1)
.WillOnce(Return(0));
EXPECT_CALL(*g_fileIOMock, close(_))
.Times(4)
.WillOnce(Return(0))
.WillOnce(Return(0))
.Times(2)
.WillOnce(Return(0))
.WillOnce(Return(0));

Expand Down Expand Up @@ -1361,9 +1357,7 @@ TEST_F(dcaTestFixture, getDCAResultsInVector_3)
.WillOnce(Return(0))
.WillOnce(Return(0));
EXPECT_CALL(*g_fileIOMock, close(_))
.Times(6)
.WillOnce(Return(0))
.WillOnce(Return(0))
.Times(4)
.WillOnce(Return(0))
.WillOnce(Return(0))
.WillOnce(Return(0))
Expand Down Expand Up @@ -1582,9 +1576,7 @@ TEST_F(dcaTestFixture, getGrepResults_success)
.Times(1)
.WillOnce(Return(0));
EXPECT_CALL(*g_fileIOMock, close(_))
.Times(4)
.WillOnce(Return(0))
.WillOnce(Return(0))
.Times(2)
.WillOnce(Return(0))
.WillOnce(Return(0));

Expand Down
Loading