Commit c5428095 authored by Moritz Lipp's avatar Moritz Lipp

Use g_strndup instead of strdup in girara_file_read_line

parent a325cacc
......@@ -352,7 +352,7 @@ config_parse(girara_session_t* session, const char* path)
while ((line = girara_file_read_line(file)) != NULL) {
/* skip empty lines and comments */
if (strlen(line) == 0 || strchr(COMMENT_PREFIX, line[0]) != NULL) {
free(line);
g_free(line);
continue;
}
......@@ -361,7 +361,7 @@ config_parse(girara_session_t* session, const char* path)
girara_list_t* argument_list = girara_list_new();
if (argument_list == NULL) {
free(line);
g_free(line);
fclose(file);
return false;
}
......@@ -375,7 +375,7 @@ config_parse(girara_session_t* session, const char* path)
} else {
girara_list_free(argument_list);
fclose(file);
free(line);
g_free(line);
return false;
}
......@@ -426,7 +426,7 @@ config_parse(girara_session_t* session, const char* path)
line_number++;
girara_list_free(argument_list);
g_strfreev(argv);
free(line);
g_free(line);
}
fclose(file);
......
......@@ -215,7 +215,7 @@ START_TEST(test_file_read) {
char* line = girara_file_read_line(file);
fail_unless(g_strcmp0(line, LINES[i]) == 0, "Line doesn't match (got: %s, expected: %s)",
line, LINES[i], NULL);
free(line);
g_free(line);
}
fclose(file);
......
......@@ -258,7 +258,7 @@ girara_file_read_line(FILE* file)
return NULL;
}
char* copy = strndup(line, size);
char* copy = g_strndup(line, size);
if (copy == NULL) {
return NULL;
}
......@@ -287,7 +287,10 @@ girara_file_read_line(FILE* file)
/* remove the trailing line deliminator */
g_strdelimit(line, "\n\r", '\0');
return line;
char* duplicate = g_strdup(line);
free(line);
return duplicate;
}
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment