Skip to content

Commit 7c9796a

Browse files
fix: get_stat() memleak (#25)
This removes the heap allocation, effectively fixing the memory leak. --------- Co-authored-by: Spenser Black <[email protected]>
1 parent d515578 commit 7c9796a

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

src/fetchfetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <string.h>
2323

2424
int main(int argc, char *argv[]) {
25-
FetchStat *stats;
25+
FetchStat stats[STATS_SIZE];
2626
bool ok = parse_args(argc, argv);
2727
const char *label;
2828
int label_len;
@@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
4040
return 0;
4141
}
4242

43-
stats = get_stats();
43+
get_stats(stats);
4444
for (int line_index = 0; line_index < ART_HEIGHT || line_index < STATS_SIZE;
4545
line_index++) {
4646
if (line_index < ART_HEIGHT) {

src/stats.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ char *screenfetch() {
120120
return extract_named_version(out, "screenFetch - Version ");
121121
}
122122

123-
FetchStat *get_stats() {
124-
FetchStat *stats = malloc(STATS_SIZE * sizeof(FetchStat));
123+
void get_stats(FetchStat stats[STATS_SIZE]) {
125124
stats[0].label = "Fastfetch";
126125
stats[0].version = fastfetch();
127126
stats[1].label = "fetchfetch";
@@ -136,5 +135,4 @@ FetchStat *get_stats() {
136135
stats[5].version = uwufetch();
137136
stats[6].label = "screenFetch";
138137
stats[6].version = screenfetch();
139-
return stats;
140138
}

src/stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ char *screenfetch();
5555
/**
5656
* Gets all stats.
5757
*/
58-
FetchStat *get_stats();
58+
void get_stats(FetchStat stats[STATS_SIZE]);
5959

6060
#endif

0 commit comments

Comments
 (0)