From 2af0d6f1a44f4a3ce7983bf47ee81f60c313246e Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Wed, 26 Sep 2012 15:32:38 +0200 Subject: [PATCH] Be careful with memory, some fixes for that. --- modules/csync_owncloud.c | 1 + src/csync_statedb.c | 2 +- src/csync_update.c | 9 +++++++-- src/csync_util.c | 2 +- src/vio/csync_vio_file_stat.c | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/csync_owncloud.c b/modules/csync_owncloud.c index e6893964b..4163e32ef 100644 --- a/modules/csync_owncloud.c +++ b/modules/csync_owncloud.c @@ -455,6 +455,7 @@ static void post_request_hook(ne_request *req, void *userdata, const ne_status * } else if( *sc_end == ';' ) { /* We are at the end of the session key. */ int keylen = sc_end-sc_val; + if( key ) SAFE_FREE(key); key = c_malloc(keylen+1); strncpy( key, sc_val, keylen ); key[keylen] = '\0'; diff --git a/src/csync_statedb.c b/src/csync_statedb.c index b4238f266..e51e1abab 100644 --- a/src/csync_statedb.c +++ b/src/csync_statedb.c @@ -318,7 +318,7 @@ static int _insert_metadata_visitor(void *obj, void *data) { fs->mode, fs->modtime, fs->type, - fs->md5); + fs->md5 ? fs->md5 : ""); /* * The phash needs to be long long unsigned int or it segfaults on PPC diff --git a/src/csync_update.c b/src/csync_update.c index 3be0d899e..997a19cdd 100644 --- a/src/csync_update.c +++ b/src/csync_update.c @@ -413,10 +413,15 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, } if( ctx->current == LOCAL_REPLICA ) { + char *md5 = NULL; int len = strlen( path ); uint64_t h = c_jhash64((uint8_t *) path, len, 0); - fs->md5 = csync_statedb_get_uniqId( ctx, h, fs ); - fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5; + md5 = csync_statedb_get_uniqId( ctx, h, fs ); + if( md5 ) { + SAFE_FREE(fs->md5); + fs->md5 = md5; + fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5; + } CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID read from Database: %s -> %s", path, fs->md5 ? fs->md5 : "" ); } diff --git a/src/csync_util.c b/src/csync_util.c index 6ac8972fd..c4f49629b 100644 --- a/src/csync_util.c +++ b/src/csync_util.c @@ -230,7 +230,7 @@ static int _merge_file_trees_visitor(void *obj, void *data) { if( tfs && tfs->md5 ) { if( fs->md5 ) SAFE_FREE(fs->md5); fs->md5 = c_strdup( tfs->md5 ); - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "PRE UPDATED %s: %s <-> %s", fs->path, fs->md5, tfs->md5); + CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "PRE UPDATED %s: %s", fs->path, fs->md5); } else { CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "md5 is empty in merger!"); } diff --git a/src/vio/csync_vio_file_stat.c b/src/vio/csync_vio_file_stat.c index 118b5c5ff..352b8e83c 100644 --- a/src/vio/csync_vio_file_stat.c +++ b/src/vio/csync_vio_file_stat.c @@ -30,7 +30,7 @@ csync_vio_file_stat_t *csync_vio_file_stat_new(void) { if (file_stat == NULL) { return NULL; } - + file_stat->md5 = NULL; return file_stat; }