diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-16 10:04:28 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-11-18 16:21:12 +0100 |
commit | fefcbb9710c87dcadab7dba5af52cb94b06625ac (patch) | |
tree | f16f8630b776960aef159079b6737b97ba268695 | |
parent | 9d189b6091a7011bfac8a9c09af750614d82a10d (diff) |
filemap xattr: simplify error handling, freeing
- Some of the error/cleanup paths are merged.
- Struct fields don't have to be set to NULL if the entire struct is
free'd immediately after.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | bin/gensquashfs/filemap_xattr.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/bin/gensquashfs/filemap_xattr.c b/bin/gensquashfs/filemap_xattr.c index 0b73d36..4c35c2e 100644 --- a/bin/gensquashfs/filemap_xattr.c +++ b/bin/gensquashfs/filemap_xattr.c @@ -153,30 +153,27 @@ xattr_open_map_file(const char *path) { } map = calloc(1, sizeof(struct XattrMap)); - if (map == NULL) { - fclose(file); - return NULL; - } + if (map == NULL) + goto fail_close; while (getline(&line, &line_size, file) != -1) { if (strncmp(NEW_FILE_START, line, strlen(NEW_FILE_START)) == 0) { - if (parse_file_name(line, map) < 0) { - fclose(file); - xattr_close_map_file(map); - return NULL; - } + if (parse_file_name(line, map) < 0) + goto fail; } else if ((p = strchr(line, '=')) && map->patterns) { - if (parse_xattr(line, p, map) < 0) { - fclose(file); - xattr_close_map_file(map); - return NULL; - } + if (parse_xattr(line, p, map) < 0) + goto fail; } } free(line); fclose(file); return map; +fail: + xattr_close_map_file(map); +fail_close: + fclose(file); + return NULL; } void @@ -189,13 +186,10 @@ xattr_close_map_file(void *xattr_map) { struct XattrMapEntry *entry = file->entries; file->entries = entry->next; free(entry->key); - entry->key = NULL; free(entry->value); - entry->value = NULL; free(entry); } free(file->path); - file->path = NULL; free(file); } free(xattr_map); |