Skip to content
Snippets Groups Projects
Commit c32d7bae authored by Andreas Gampe's avatar Andreas Gampe
Browse files

fc_sort: Fix leaks

Use the getline API correctly: keep a single buffer as long as
possible, and let the callee handle re-allocation. Move the final
free out of the loop.

Release the head of the linked list.

Bug: 37757586
Test: ASAN_OPTIONS= SANITIZE_HOST=address mmma system/sepolicy
Change-Id: I42424acba7cd68c1b9a7a43e916a421ac3e253f7
parent 608969b3
No related branches found
No related tags found
No related merge requests found
...@@ -350,6 +350,7 @@ int main(int argc, char *argv[]) ...@@ -350,6 +350,7 @@ int main(int argc, char *argv[])
/* Parse the file into a file_context linked list. */ /* Parse the file into a file_context linked list. */
line_buf = NULL; line_buf = NULL;
buf_len = 0;
while ( getline(&line_buf, &buf_len, in_file) != -1 ){ while ( getline(&line_buf, &buf_len, in_file) != -1 ){
line_len = strlen(line_buf); line_len = strlen(line_buf);
...@@ -478,15 +479,13 @@ int main(int argc, char *argv[]) ...@@ -478,15 +479,13 @@ int main(int argc, char *argv[])
current->next = temp; current->next = temp;
current = current->next; current = current->next;
lines++; lines++;
free(line_buf);
line_buf = NULL;
} }
free(line_buf);
fclose(in_file); fclose(in_file);
/* Create the bucket linked list from the earlier linked list. */ /* Create the bucket linked list from the earlier linked list. */
current = head->next; current = head->next;
free(head);
bcurrent = master = bcurrent = master =
(file_context_bucket_t *) (file_context_bucket_t *)
malloc(sizeof(file_context_bucket_t)); malloc(sizeof(file_context_bucket_t));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment