summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcbruder <cbruder@ubuntu>2013-02-19 10:37:10 +0100
committercbruder <cbruder@ubuntu>2013-02-19 10:37:10 +0100
commit5e5808c63079490ccd4f74d5bfe79ce9efbba0ea (patch)
treef7b46d94f1f94b27aebbbda1113c2f41c851d106
parent80a2142d2ba11f0e98c9debee06d9b1f7d5a5d5a (diff)
downloadpersistence-client-library-5e5808c63079490ccd4f74d5bfe79ce9efbba0ea.tar.gz
Improved quality, by fixing issues detected by Coverity Scan:
-CID 984503: NO_EFFECT -CID 984505: OVERRUN -CID 984507: RESOURCE_LEAK -CID 984508: RESOURCE_LEAK
-rw-r--r--src/persistence_client_library.c4
-rw-r--r--src/persistence_client_library_custom_loader.c4
-rw-r--r--src/persistence_client_library_db_access.c3
-rw-r--r--test/persistence_client_library_test.c5
4 files changed, 12 insertions, 4 deletions
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index b5e3c0b..9b285c1 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -34,7 +34,7 @@
-#define ENABLE_DBUS_INTERFACE 1
+#define ENABLE_DBUS_INTERFACE 0
extern char* __progname;
@@ -81,7 +81,7 @@ void pers_library_init(void)
#endif
// clear the open file descriptor array
- memset(gOpenFdArray, MaxPersHandle, sizeof(int));
+ memset(gOpenFdArray, 0, MaxPersHandle * sizeof(int));
/// get custom library names to load
status = get_custom_libraries();
diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c
index ac61e9b..bbb2024 100644
--- a/src/persistence_client_library_custom_loader.c
+++ b/src/persistence_client_library_custom_loader.c
@@ -156,6 +156,8 @@ int get_custom_libraries()
}
else
{
+ munmap(configFileMap, buffer.st_size); // @CB: Add
+ close(fd); // @CB: Add // close file descriptor before return
return EPERS_OUTOFBOUNDS; // out of array bounds
}
@@ -199,7 +201,6 @@ int get_custom_libraries()
gNumOfCustomLibraries = i; // remember the number of loaded libraries
munmap(configFileMap, buffer.st_size);
- close(fd);
// debugging only
/* printf("get_custom_libraries - found [ %d ] libraries \n", gNumOfCustomLibraries);
@@ -214,6 +215,7 @@ int get_custom_libraries()
rval = EPERS_CONFIGMAPFAILED;
printf("load config file error - mapping of file failed");
}
+ close(fd);
}
else
{
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index 71fc930..545f005 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -74,7 +74,8 @@ itzam_btree* pers_db_open(PersistenceInfo_s* info, const char* dbPath)
// create array index: index is a combination of resource config table type and group
arrayIdx = info->configKey.storage + info->context.ldbid ;
- if(arrayIdx <= DbTableSize)
+ //if(arrayIdx <= DbTableSize)
+ if(arrayIdx < DbTableSize)
{
if(gBtreeCreated[arrayIdx][info->configKey.policy] == 0)
{
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 945ec61..d7d1375 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -492,6 +492,9 @@ START_TEST(test_DataFile)
ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
+ ret = pclFileClose(fd);
+ fail_unless(ret == 0, "Failed to close file");
+
// map file ------------------------------------------------------
fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
@@ -507,6 +510,8 @@ START_TEST(test_DataFile)
size = pclFileGetSize(1024);
fail_unless(ret == 0, "Got size, but should not");
+ ret = pclFileClose(fd);
+ fail_unless(ret == 0, "Failed to close file");
free(writeBuffer);
}