aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-04-26 00:54:48 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-04-26 00:54:58 -0400
commit2c8c1166d81a5c0fe6f335742ee24319ce60bfa8 (patch)
treec58e738644f9595fae67e2ade0ecec35f8b7eca4 /main.c
parente71c07b9d5cc1236ca08536ae052faa5fc6b9096 (diff)
downloadwhatami-2c8c1166d81a5c0fe6f335742ee24319ce60bfa8.tar.gz
Use static storage
* Almost everything returned by the system is immutable * Fixed block_device array initialization and alphabetical sorting * Free memory where possible
Diffstat (limited to 'main.c')
-rw-r--r--main.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/main.c b/main.c
index ca59c79..e173ae5 100644
--- a/main.c
+++ b/main.c
@@ -1,9 +1,10 @@
#include "common.h"
static int cmp_block_device(const void *aa, const void *bb) {
- const char *a = ((struct Block_Device *) aa)->path;
- const char *b = ((struct Block_Device *) bb)->path;
- return strcmp(a, b) == 0;
+ struct Block_Device *a = *(struct Block_Device **) aa;
+ struct Block_Device *b = *(struct Block_Device **) bb;
+
+ return strcmp(a->path, b->path);
}
int main() {
@@ -53,7 +54,7 @@ int main() {
if (!block_device) {
fprintf(stderr, "Unable to enumerate block devices\n");
} else {
- qsort(block_device, device_count, sizeof(block_device), cmp_block_device);
+ qsort(block_device, device_count, sizeof(block_device[0]), cmp_block_device);
for (size_t bd = 0; bd < device_count; bd++) {
struct Block_Device *p;
p = block_device[bd];
@@ -61,5 +62,14 @@ int main() {
}
}
+ for (size_t i = 0; i < device_count; i++) {
+ free(block_device[i]->path);
+ free(block_device[i]->model);
+ free(block_device[i]);
+ }
+ free(block_device);
+ free(distro_name);
+ free(distro_version);
+
return 0;
}