fixed some memory leaks
This commit is contained in:
29
colors.c
29
colors.c
@ -1,6 +1,7 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <bits/types/FILE.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
#include "defines.h"
|
||||
@ -57,70 +58,57 @@ void colors_init() {
|
||||
short fg;
|
||||
short bg;
|
||||
|
||||
char supported_filetype_count = 9;
|
||||
char initial_pass = 0;
|
||||
while ((tmp = getline(&line, &size, dircolors)) != -1 && initial_pass != supported_filetype_count) {
|
||||
while ((tmp = getline(&line, &size, dircolors)) != -1) {
|
||||
fg = 7;
|
||||
bg = 0;
|
||||
token = strtok(line, " ");
|
||||
if (token[0] != '#' && token[0] != '\n') {
|
||||
if (!strcmp(token, "DIR")) {
|
||||
initial_pass++;
|
||||
if (line[0] == '.') {
|
||||
color_count++;
|
||||
} else if (!strcmp(token, "DIR")) {
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(1, fg, bg); /* directory */
|
||||
} else if (!strcmp(token, "EXEC")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(2, fg, bg); /* exec */
|
||||
} else if (!strcmp(token, "RESET")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(3, fg, bg); /* regular file */
|
||||
} else if (!strcmp(token, "LINK")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(4, fg, bg); /* symlink */
|
||||
} else if (!strcmp(token, "BLK")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(5, fg, bg); /* block device */
|
||||
} else if (!strcmp(token, "CHR")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(6, fg, bg); /* character device */
|
||||
} else if (!strcmp(token, "SOCK")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(7, fg, bg); /* socket */
|
||||
} else if (!strcmp(token, "FIFO")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(8, fg, bg); /* fifo */
|
||||
} else if (!strcmp(token, "ORPHAN")){
|
||||
initial_pass++;
|
||||
parse_colors(line, &fg, &bg);
|
||||
init_pair(9, fg, bg); /* orphan */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* checks for only extensions (*.[extension], includes the '.') as the filetypes are handled seperately */
|
||||
while ((tmp = getline(&line, &size, dircolors)) != -1) {
|
||||
if (line[0] == '.') {
|
||||
color_count++;
|
||||
}
|
||||
}
|
||||
rewind(dircolors);
|
||||
|
||||
colors = malloc(sizeof(color) * color_count);
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
/* proper pass, reads all defined extensions within /etc/DIR_COLORS */
|
||||
while ((tmp = getline(&line, &size, dircolors)) != -1) {
|
||||
fg = 7;
|
||||
bg = 0;
|
||||
printf("%d\n",j);
|
||||
if (line[0] == '.') {
|
||||
extension = strtok(line, " ");
|
||||
colors[i].file_extension = malloc(sizeof(extension));
|
||||
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||
strcpy(colors[i].file_extension, extension);
|
||||
|
||||
colors[i].color_pair = i+11;
|
||||
@ -129,6 +117,7 @@ void colors_init() {
|
||||
i++;
|
||||
|
||||
}
|
||||
j++;
|
||||
}
|
||||
} else {
|
||||
init_pair(0, COLOR_WHITE, COLOR_BLACK); /* unknown file */
|
||||
|
Reference in New Issue
Block a user