summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Vijay <abhishek.v@samsung.com>2019-01-03 18:21:30 +0530
committerAbhishek Vijay <abhishek.v@samsung.com>2019-01-03 18:21:30 +0530
commit13367b742baaee76ef8c54b6f917984954852be2 (patch)
treefa9e169ab7a3dc80b91f73ef4f770761820812cb
parentee4c7a682ef0b82b810d4f720d15065364ba570d (diff)
downloadsync-manager-accepted/tizen_4.0_unified.tar.gz
sync-manager-accepted/tizen_4.0_unified.tar.bz2
sync-manager-accepted/tizen_4.0_unified.zip
Change-Id: I53c64ea8acaa71d94993446723f741be902da076 Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
-rw-r--r--packaging/sync-manager.spec2
-rw-r--r--src/sync-client/sync_adapter.c4
-rw-r--r--src/sync-client/sync_manager.c2
-rw-r--r--src/sync-service/SyncManager_CurrentSyncJobQueue.cpp2
-rw-r--r--src/sync-service/SyncManager_RepositoryEngine.cpp111
-rw-r--r--src/sync-service/SyncManager_SyncManager.cpp13
6 files changed, 102 insertions, 32 deletions
diff --git a/packaging/sync-manager.spec b/packaging/sync-manager.spec
index ec83899..d12395a 100644
--- a/packaging/sync-manager.spec
+++ b/packaging/sync-manager.spec
@@ -2,7 +2,7 @@
%global __provides_exclude_from ^.*\\.extension-calendar
Name: sync-service
-Version: 0.3.39
+Version: 0.3.40
Release: 1
License: Apache-2.0
Summary: Sync manager daemon
diff --git a/src/sync-client/sync_adapter.c b/src/sync-client/sync_adapter.c
index 0bf4184..ed91664 100644
--- a/src/sync-client/sync_adapter.c
+++ b/src/sync-client/sync_adapter.c
@@ -72,15 +72,19 @@ __sync_adapter_on_start_sync(TizenSyncAdapter *pObject,
LOG_LOGD("Received start sync request in sync adapter: params account[%d] jobname [%s] Data sync [%s]", accountId, pSyncJobName, is_data_sync ? "YES" : "NO");
char *command_line = proc_get_cmdline_self();
+ if (command_line == NULL)
+ return false;
if (!g_sync_adapter) {
LOG_LOGD("Sync adapter is already released");
+ free(command_line);
return false;
}
if (g_sync_adapter->__syncRunning) {
LOG_LOGD("Sync already running");
tizen_sync_adapter_call_send_result_sync(pObject, command_line, (int)SYNC_STATUS_SYNC_ALREADY_IN_PROGRESS, pSyncJobName, NULL, NULL);
+ free(command_line);
return true;
}
diff --git a/src/sync-client/sync_manager.c b/src/sync-client/sync_manager.c
index 79d3188..ae85dcb 100644
--- a/src/sync-client/sync_manager.c
+++ b/src/sync-client/sync_manager.c
@@ -171,6 +171,8 @@ static int _sync_get_error_code(bool is_success, GError *error)
}
}
}
+ if (remote_error)
+ g_free(remote_error);
}
/* All undocumented errors mapped to SYNC_ERROR_UNKNOWN */
return SYNC_ERROR_UNKNOWN;
diff --git a/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp b/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp
index cb3fbbe..201ae54 100644
--- a/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp
+++ b/src/sync-service/SyncManager_CurrentSyncJobQueue.cpp
@@ -191,6 +191,8 @@ CurrentSyncJobQueue::ToKey(account_h account, string capability) {
ss << id;
key.append("id:").append(ss.str()).append("name:").append(pName).append("capability:").append(capability.c_str());
+ if (pName)
+ free(pName);
return key;
}
diff --git a/src/sync-service/SyncManager_RepositoryEngine.cpp b/src/sync-service/SyncManager_RepositoryEngine.cpp
index 980afa8..f97d916 100644
--- a/src/sync-service/SyncManager_RepositoryEngine.cpp
+++ b/src/sync-service/SyncManager_RepositoryEngine.cpp
@@ -141,14 +141,10 @@ RepositoryEngine::~RepositoryEngine(void) {
RepositoryEngine::RepositoryEngine(void) {
- if (pthread_mutex_init(&__capabilityInfoMutex, NULL) != 0) {
+ if (pthread_mutex_init(&__capabilityInfoMutex, NULL) != 0)
LOG_LOGD("__capabilityInfoMutex init failed"); /* LCOV_EXCL_LINE */
- return;
- }
- if (pthread_mutex_init(&__syncDBReadWriteMutex, NULL) != 0) {
+ if (pthread_mutex_init(&__syncDBReadWriteMutex, NULL) != 0)
LOG_LOGD("__syncDBReadWriteMutex init failed"); /* LCOV_EXCL_LINE */
- return;
- }
}
@@ -333,7 +329,6 @@ RepositoryEngine::ReadSyncJobsData(void) {
/* process for removing previous data */
xmlNodePtr rootNode;
- stringstream ss;
doc = xmlNewDoc(_VERSION);
@@ -399,8 +394,23 @@ RepositoryEngine::ReadSyncAdapters(void) {
while (cur != NULL) {
if (!xmlStrcmp(cur->name, XML_NODE_SYNCADAPTER)) {
xmlChar* pServiceAppId = xmlGetProp(cur, XML_ATTR_SYNCADAPTER_SERVICE_APP_ID);
+ if (pServiceAppId == NULL) {
+ LOG_LOGD("Found empty service_app_id while parsing syncadapters.xml");
+ xmlFreeDoc(doc);
+ return;
+ }
+
xmlChar* pPackageId = xmlGetProp(cur, XML_ATTR_PACKAGE_ID);
+ if (pPackageId == NULL) {
+ LOG_LOGD("Found empty package_id while parsing syncadapters.xml");
+ xmlFree(pServiceAppId);
+ xmlFreeDoc(doc);
+ return;
+ }
+
xmlChar* pAppStatus = xmlGetProp(cur, XML_ATTR_APP_STATUS);
+ if (pAppStatus == NULL)
+ LOG_LOGD("Found empty app_status while parsing syncadapters.xml");
pkgmgrinfo_appinfo_h handle_appinfo;
if (pkgmgrinfo_appinfo_get_appinfo((char*)pServiceAppId, &handle_appinfo) == PMINFO_R_OK) {
@@ -415,11 +425,8 @@ RepositoryEngine::ReadSyncAdapters(void) {
} else {
pAggregator->HandlePackageUninstalled((char*)pPackageId);
}
-
- if (pServiceAppId)
- xmlFree(pServiceAppId);
- if (pPackageId)
- xmlFree(pPackageId);
+ xmlFree(pServiceAppId);
+ xmlFree(pPackageId);
if (pAppStatus)
xmlFree(pAppStatus);
}
@@ -430,7 +437,6 @@ RepositoryEngine::ReadSyncAdapters(void) {
/* process for removing previous data */
xmlNodePtr rootNode;
- stringstream ss;
doc = xmlNewDoc(_VERSION);
@@ -1677,15 +1683,11 @@ static void bundIterCb(const char *key, const char *value, void *user_data) {
UserValue = const_cast<char *>(value);
}
-
-static std::string setEmpty(void) {
- return "";
-}
-
-
int
RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId,
const char *SyncType, int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+ bool user_data_available = false;
+
sqlite3 *db = NULL;
db = db_open();
if (!db) {
@@ -1708,11 +1710,13 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
char noRetry[2] = { 0, };
snprintf(noRetry, sizeof(noRetry) - 1, "%d", Option & SYNC_OPTION_NO_RETRY);
- UserKey = const_cast<char *>(setEmpty().c_str());
- UserValue = const_cast<char *>(setEmpty().c_str());
-
- if (UserData)
+ if (UserData) {
bundle_iterate(UserData, bundIterCb, NULL);
+ } else {
+ UserKey = strdup("");
+ UserValue = strdup("");
+ user_data_available = true;
+ }
char *search_query = NULL;
char *insert_query = NULL;
@@ -1726,6 +1730,11 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
sqlite3_finalize(stmt);
sqlite3_free(search_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return -1;
@@ -1746,6 +1755,11 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
sqlite3_finalize(stmt);
sqlite3_free(search_query);
sqlite3_free(insert_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return -1;
@@ -1758,6 +1772,11 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
sqlite3_finalize(stmt);
sqlite3_free(search_query);
sqlite3_free(insert_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return -1;
@@ -1770,6 +1789,11 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
sqlite3_reset(stmt);
sqlite3_finalize(stmt);
sqlite3_free(search_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return UpdateSyncJobToDB(SvcAppId, UserId, AppStatus, JobId, SyncType, AccountId, JobName, Interval, Option, UserData);
@@ -1778,6 +1802,11 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
sqlite3_reset(stmt);
sqlite3_finalize(stmt);
sqlite3_free(search_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return -1;
@@ -1790,6 +1819,12 @@ RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, i
LOG_LOGD("Insert sync job fail : invalid service-app-id");
}
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
+
db_close(db);
LOG_LOGD("sync-manager DB close");
@@ -1860,7 +1895,9 @@ RepositoryEngine::UpdateAppStatusToDB(const char *SvcAppId, const char *PkgName,
int
RepositoryEngine::UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char *AppStatus, int JobId, const char *SyncType,
- int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+ bool user_data_available = false;
+
sqlite3 *db = NULL;
db = db_open();
if (!db) {
@@ -1883,11 +1920,13 @@ RepositoryEngine::UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char
char noRetry[2] = { 0, };
snprintf(noRetry, sizeof(noRetry) - 1, "%d", Option & SYNC_OPTION_NO_RETRY);
- UserKey = const_cast<char *>(setEmpty().c_str());
- UserValue = const_cast<char *>(setEmpty().c_str());
-
- if (UserData)
+ if (UserData) {
bundle_iterate(UserData, bundIterCb, NULL);
+ } else {
+ UserKey = strdup("");
+ UserValue = strdup("");
+ user_data_available = true;
+ }
char *update_query = NULL;
@@ -1905,6 +1944,11 @@ RepositoryEngine::UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char
LOG_LOGD("prepare : update query[%s] ret[%d] err_msg[%s]", update_query, ret, sqlite3_errmsg(db));
sqlite3_finalize(stmt);
sqlite3_free(update_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return -1;
@@ -1918,6 +1962,11 @@ RepositoryEngine::UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char
sqlite3_reset(stmt);
sqlite3_finalize(stmt);
sqlite3_free(update_query);
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
db_close(db);
LOG_LOGD("sync-manager DB close");
return -1;
@@ -1933,6 +1982,12 @@ RepositoryEngine::UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char
LOG_LOGD("update sync job fail : invalid service-app-id");
}
+ if (user_data_available && UserKey && UserValue) {
+ free(UserKey);
+ free(UserValue);
+ UserKey = UserValue = NULL;
+ }
+
db_close(db);
LOG_LOGD("sync-manager DB close");
diff --git a/src/sync-service/SyncManager_SyncManager.cpp b/src/sync-service/SyncManager_SyncManager.cpp
index 33b4544..aed6c9a 100644
--- a/src/sync-service/SyncManager_SyncManager.cpp
+++ b/src/sync-service/SyncManager_SyncManager.cpp
@@ -866,8 +866,8 @@ SyncManager::AreAccountsEqual(account_h account1, account_h account2) {
isEqual = false;
}
- char* pName1;
- char* pName2;
+ char* pName1 = NULL;
+ char* pName2 = NULL;
if (account_get_user_name(account1, &pName1) < 0) {
isEqual = false;
}
@@ -878,7 +878,14 @@ SyncManager::AreAccountsEqual(account_h account1, account_h account2) {
if (id1 == id2 && strcmp(pName1, pName2) == 0) {
isEqual = true;
}
-
+ if (pName1) {
+ free(pName1);
+ pName1 = NULL;
+ }
+ if (pName2) {
+ free(pName2);
+ pName2 = NULL;
+ }
return isEqual;
}