hs: remove redundant file handle in HSLoadCache

HSLoadCache opened the cache file but never used the resulting handle
for reading. The actual read was done by HSReadStream which opened
the same file independently.

Removed the unused fopen/fclose pair and flattened the control flow.

Ticket: 8325
pull/14908/head
Lukas Sismis 6 months ago committed by Victor Julien
parent 569ba3d26f
commit d754b28717

@ -133,38 +133,30 @@ int HSLoadCache(hs_database_t **hs_db, const char *hs_db_hash, const char *dirpa
if (!SCPathExists(hash_file_static)) if (!SCPathExists(hash_file_static))
return -1; return -1;
FILE *db_cache = fopen(hash_file_static, "r");
char *buffer = NULL; char *buffer = NULL;
if (db_cache) { size_t buffer_size;
size_t buffer_size; buffer = HSReadStream(hash_file_static, &buffer_size);
buffer = HSReadStream(hash_file_static, &buffer_size); if (!buffer) {
if (!buffer) { SCLogWarning("Hyperscan cached DB file %s cannot be read", hash_file_static);
SCLogWarning("Hyperscan cached DB file %s cannot be read", hash_file_static); return -1;
ret = -1; }
goto freeup;
}
hs_error_t error = hs_deserialize_database(buffer, buffer_size, hs_db);
if (error != HS_SUCCESS) {
SCLogWarning("Failed to deserialize Hyperscan database of %s: %s", hash_file_static,
HSErrorToStr(error));
ret = -1;
goto freeup;
}
ret = 0; hs_error_t error = hs_deserialize_database(buffer, buffer_size, hs_db);
/* Touch file to update modification time so active caches are retained. */ if (error != HS_SUCCESS) {
if (SCTouchFile(hash_file_static) != 0) { SCLogWarning("Failed to deserialize Hyperscan database of %s: %s", hash_file_static,
SCLogDebug("Failed to update mtime for %s", hash_file_static); HSErrorToStr(error));
} ret = -1;
goto freeup; goto freeup;
} }
ret = 0;
/* Touch file to update modification time so active caches are retained. */
if (SCTouchFile(hash_file_static) != 0) {
SCLogDebug("Failed to update mtime for %s", hash_file_static);
}
freeup: freeup:
if (db_cache) SCFree(buffer);
fclose(db_cache);
if (buffer)
SCFree(buffer);
return ret; return ret;
} }

Loading…
Cancel
Save