Be careful with memory, some fixes for that.

This commit is contained in:
Klaas Freitag 2012-09-26 15:32:38 +02:00
parent 004f5ccce6
commit 2af0d6f1a4
5 changed files with 11 additions and 5 deletions

View file

@ -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';

View file

@ -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 : "<empty>");
/*
* The phash needs to be long long unsigned int or it segfaults on PPC

View file

@ -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 : "<NULL>" );
}

View file

@ -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!");
}

View file

@ -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;
}