diff --git a/source/dcautil/dca.c b/source/dcautil/dca.c index 616aa88c..581a7832 100644 --- a/source/dcautil/dca.c +++ b/source/dcautil/dca.c @@ -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; @@ -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); } } @@ -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); @@ -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) { @@ -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) @@ -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); @@ -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; } } @@ -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); diff --git a/source/test/dcautils/dcautilTest.cpp b/source/test/dcautils/dcautilTest.cpp index 43ab1afe..71964594 100644 --- a/source/test/dcautils/dcautilTest.cpp +++ b/source/test/dcautils/dcautilTest.cpp @@ -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)); @@ -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)); @@ -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)) @@ -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));