summaryrefslogtreecommitdiff
path: root/src/readahead
diff options
context:
space:
mode:
Diffstat (limited to 'src/readahead')
-rw-r--r--src/readahead/readahead-collect.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 32888add01..6b748664c3 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -536,8 +536,7 @@ done:
HASHMAP_FOREACH_KEY(q, p, files, i)
pack_file(pack, p, on_btrfs);
} else {
- struct item *ordered, *j;
- unsigned k, n;
+ unsigned n;
/* On rotating media, order things by the block
* numbers */
@@ -545,25 +544,31 @@ done:
log_debug("Ordering...");
n = hashmap_size(files);
- if (!(ordered = new(struct item, n))) {
- r = log_oom();
- goto finish;
- }
-
- j = ordered;
- HASHMAP_FOREACH_KEY(q, p, files, i) {
- memcpy(j, q, sizeof(struct item));
- j++;
- }
+ if (n) {
+ _cleanup_free_ struct item *ordered;
+ struct item *j;
+ unsigned k;
+
+ ordered = new(struct item, n);
+ if (!ordered) {
+ r = log_oom();
+ goto finish;
+ }
- assert(ordered + n == j);
+ j = ordered;
+ HASHMAP_FOREACH_KEY(q, p, files, i) {
+ memcpy(j, q, sizeof(struct item));
+ j++;
+ }
- qsort(ordered, n, sizeof(struct item), qsort_compare);
+ assert(ordered + n == j);
- for (k = 0; k < n; k++)
- pack_file(pack, ordered[k].path, on_btrfs);
+ qsort(ordered, n, sizeof(struct item), qsort_compare);
- free(ordered);
+ for (k = 0; k < n; k++)
+ pack_file(pack, ordered[k].path, on_btrfs);
+ } else
+ log_warning("No pack files");
}
log_debug("Finalizing...");