diff options
author | Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> | 2021-08-05 01:43:01 +0200 |
---|---|---|
committer | Eric Engestrom <eric@engestrom.ch> | 2021-08-09 08:32:03 +0100 |
commit | 730c326f8e554d94700ae0e3cbd186a46b90b8a4 (patch) | |
tree | 9cf7e631680710a245baba6d1c77fc1ed1286810 | |
parent | eb865f3b90cccb36e2f8898f442b10ba2e186488 (diff) |
util/fossilize_db: Only allocate entries after full read.
Should void leaking entries on read failure.
Fixes: 2ec1bff0f3a "util/fossilize_db: Split out reading the index."
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12204>
(cherry picked from commit d2d642cc014af75f0396e04528b29f9a61f91043)
-rw-r--r-- | .pick_status.json | 2 | ||||
-rw-r--r-- | src/util/fossilize_db.c | 21 |
2 files changed, 12 insertions, 11 deletions
diff --git a/.pick_status.json b/.pick_status.json index 452b024c965..1d39e689b41 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -166,7 +166,7 @@ "description": "util/fossilize_db: Only allocate entries after full read.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "2ec1bff0f3a4450a9739d59421dc9c9fe72c94c6" }, diff --git a/src/util/fossilize_db.c b/src/util/fossilize_db.c index 4a25d077ee4..9943a5c1100 100644 --- a/src/util/fossilize_db.c +++ b/src/util/fossilize_db.c @@ -147,29 +147,30 @@ update_foz_index(struct foz_db *foz_db, FILE *db_idx, unsigned file_idx) char hash_str[FOSSILIZE_BLOB_HASH_LENGTH + 1] = {0}; memcpy(hash_str, bytes_to_read, FOSSILIZE_BLOB_HASH_LENGTH); - struct foz_db_entry *entry = ralloc(foz_db->mem_ctx, - struct foz_db_entry); - entry->header = *header; - entry->file_idx = file_idx; - _mesa_sha1_hex_to_sha1(entry->key, hash_str); - /* read cache item offset from index file */ uint64_t cache_offset; if (fread(&cache_offset, 1, sizeof(cache_offset), db_idx) != sizeof(cache_offset)) break; - entry->offset = cache_offset; + offset += header->payload_size; + parsed_offset = offset; /* Truncate the entry's hash string to a 64bit hash for use with a * 64bit hash table for looking up file offsets. */ hash_str[16] = '\0'; uint64_t key = strtoull(hash_str, NULL, 16); - _mesa_hash_table_u64_insert(foz_db->index_db, key, entry); - offset += header->payload_size; - parsed_offset = offset; + struct foz_db_entry *entry = ralloc(foz_db->mem_ctx, + struct foz_db_entry); + entry->header = *header; + entry->file_idx = file_idx; + _mesa_sha1_hex_to_sha1(entry->key, hash_str); + + entry->offset = cache_offset; + + _mesa_hash_table_u64_insert(foz_db->index_db, key, entry); } |