Compare commits

...

2 commits

Author SHA1 Message Date
Andrea Mazzoleni
575ce99b5f Use a 64 bit hash for the buckets, just to avoid conversion warnings
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-win (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
2026-02-18 19:53:17 +01:00
Andrea Mazzoleni
7af0111c4a Fix leak on error when writing content file 2026-02-18 19:48:30 +01:00
2 changed files with 25 additions and 21 deletions

View file

@ -1434,7 +1434,7 @@ void bucket_free(struct snapraid_bucket* bucket)
void bucket_insert(tommy_hashdyn* bucket_hash, time_t time_at, block_off_t count, int justsynced)
{
unsigned hash = tommy_inthash_u32(time_at);
tommy_hash_t hash = tommy_inthash_u64(time_at);
tommy_node* i = tommy_hashdyn_bucket(bucket_hash, hash);
while (i) {
struct snapraid_bucket* entry = i->data;

View file

@ -3217,7 +3217,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3231,14 +3231,14 @@ static void* state_write_thread(void* arg)
} else {
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Unexpected hash when writing the content file '%s'.\n", serrorfile(f));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
swrite(state->hashseed, HASH_MAX, f);
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3256,14 +3256,14 @@ static void* state_write_thread(void* arg)
} else {
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
swrite(state->prevhashseed, HASH_MAX, f);
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
}
@ -3279,7 +3279,7 @@ static void* state_write_thread(void* arg)
if (!disk) {
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Internal inconsistency: Unmapped disk '%s'\n", map->name);
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3303,7 +3303,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
}
@ -3342,7 +3342,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
}
@ -3383,7 +3383,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3419,7 +3419,7 @@ static void* state_write_thread(void* arg)
default :
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Internal inconsistency: State for block %u state %u\n", v_pos, v_state);
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3438,7 +3438,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3470,7 +3470,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
}
@ -3485,7 +3485,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3498,7 +3498,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
begin = 0;
@ -3542,7 +3542,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
}
@ -3627,7 +3627,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3641,7 +3641,7 @@ static void* state_write_thread(void* arg)
if (sflush(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s' (in flush before crc). %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3655,7 +3655,7 @@ static void* state_write_thread(void* arg)
log_fatal(ECONTENT, "CRC mismatch while writing the content stream.\n");
log_fatal(ECONTENT, "DANGER! Your RAM memory is faulty! DO NOT PROCEED UNTIL FIXED!\n");
log_fatal(ECONTENT, "Try running a memory test like http://www.memtest86.com/\n");
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3663,7 +3663,7 @@ static void* state_write_thread(void* arg)
if (serror(f)) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno));
return context;
goto bail;
/* LCOV_EXCL_STOP */
}
@ -3681,9 +3681,13 @@ static void* state_write_thread(void* arg)
/* store the bucket info list */
if (context->first)
bucket_to_list(&bucket_hash, &state->bucketlist, &state->bucketcount);
tommy_hashdyn_done(&bucket_hash);
tommy_hashdyn_done(&bucket_hash);
return 0;
bail:
tommy_hashdyn_done(&bucket_hash);
return context;
}
static void state_write_content(struct snapraid_state* state, uint32_t* out_crc)