free line if getline errors

This commit is contained in:
jacekpoz 2024-02-09 15:31:30 +01:00
parent 771680ac17
commit 170e69d096
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C

View file

@ -1,5 +1,6 @@
#include <ctype.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@ -140,6 +141,9 @@ Config parse_config(FILE *config_file) {
.module_count = 0,
};
// TODO handle errors of all the function inside the while
errno = 0;
// TODO rewrite this to read the config char by char
while ((read = getline(&line, &len, config_file)) != -1) {
if (read <= 1)
@ -200,6 +204,8 @@ Config parse_config(FILE *config_file) {
free(line);
}
if (read == -1 && errno != 0)
free(line);
return config;
}