From fbb88abe85cb86fefe78dd12d075f29bb529bf96 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 4 Oct 2012 13:03:42 +0200 Subject: [PATCH] Clear memory and fix zero return type for _get_stat_by_hash --- src/csync_statedb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/csync_statedb.c b/src/csync_statedb.c index e1c214fd3..a2b536b71 100644 --- a/src/csync_statedb.c +++ b/src/csync_statedb.c @@ -449,6 +449,8 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash) { c_strlist_destroy(result); return NULL; } + /* clear the whole structure */ + ZERO_STRUCTP(st); /* * FIXME: @@ -470,18 +472,20 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash) { st->gid = atoi(result->vector[5]); st->mode = atoi(result->vector[6]); st->modtime = strtoul(result->vector[7], NULL, 10); + + if(st && result->count > 8 && result->vector[8]) { + st->type = atoi(result->vector[8]); + } + + if(result->count > 9 && result->vector[9]) { + st->md5 = c_strdup( result->vector[9] ); + } } else { CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "No result record found for phash = %llu", (long long unsigned int) phash); + SAFE_FREE(st); } - if(result->count > 8 && result->vector[8]) { - st->type = atoi(result->vector[8]); - } - - if(result->count > 9 && result->vector[9]) { - st->md5 = c_strdup( result->vector[9] ); - } c_strlist_destroy(result); return st; @@ -517,6 +521,8 @@ csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx, uint64_t inode) { c_strlist_destroy(result); return NULL; } + /* clear the whole structure */ + ZERO_STRUCTP(st); st->phash = strtoull(result->vector[0], NULL, 10); st->pathlen = atoi(result->vector[1]);