Gentoo Archives: gentoo-commits

From: Jason Zaman <perfinion@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/hardened-refpolicy:master commit in: support/
Date: Sun, 29 Oct 2017 20:43:06
Message-Id: 1509281990.9303a33ab384c0af2ad5e90e6491dc330e3e5a01.perfinion@gentoo
1 commit: 9303a33ab384c0af2ad5e90e6491dc330e3e5a01
2 Author: William Roberts <william.c.roberts <AT> intel <DOT> com>
3 AuthorDate: Tue Oct 17 18:16:23 2017 +0000
4 Commit: Jason Zaman <perfinion <AT> gentoo <DOT> org>
5 CommitDate: Sun Oct 29 12:59:50 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/hardened-refpolicy.git/commit/?id=9303a33a
7
8 fc_sort: use calloc instead of malloc
9
10 Rather than using malloc to allocated nodes and setting all the fields,
11 just use calloc.
12
13 Signed-off-by: William Roberts <william.c.roberts <AT> intel.com>
14
15 support/fc_sort.c | 10 ++--------
16 1 file changed, 2 insertions(+), 8 deletions(-)
17
18 diff --git a/support/fc_sort.c b/support/fc_sort.c
19 index 956c37b8..bfe28ca8 100644
20 --- a/support/fc_sort.c
21 +++ b/support/fc_sort.c
22 @@ -357,15 +357,11 @@ int main(int argc, char *argv[])
23 }
24
25 /* Initialize the head of the linked list. */
26 - head = current = (file_context_node_t*)malloc(sizeof(file_context_node_t));
27 + head = current = (file_context_node_t*)calloc(1, sizeof(file_context_node_t));
28 if (!head) {
29 fprintf(stderr, "Error: failure allocating memory.\n");
30 return 1;
31 }
32 - head->next = NULL;
33 - head->path = NULL;
34 - head->file_type = NULL;
35 - head->context = NULL;
36
37 /* Parse the file into a file_context linked list. */
38 line_buf = NULL;
39 @@ -390,15 +386,13 @@ int main(int argc, char *argv[])
40 continue;
41
42 /* We have a valid line - allocate a new node. */
43 - temp = (file_context_node_t *)malloc(sizeof(file_context_node_t));
44 + temp = (file_context_node_t *)calloc(1, sizeof(file_context_node_t));
45 if (!temp) {
46 free(line_buf);
47 fprintf(stderr, "Error: failure allocating memory.\n");
48 fc_free_file_context_node_list(head);
49 return 1;
50 }
51 - temp->next = NULL;
52 - memset(temp, 0, sizeof(file_context_node_t));
53
54 /* Parse out the regular expression from the line. */
55 start = i;