Commit Graph

11 Commits

Author SHA1 Message Date
William Roberts 65620e0f94 fc_sort: use calloc instead of malloc
Rather than using malloc to allocated nodes and setting all the fields,
just use calloc.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
2017-10-18 19:26:36 -07:00
Guido Trentalancia 5490639ac9 fc_sort: memory leakages
Avoid memory leakages in the fc_sort executable (now passes
all valgrind AND Clang static analyzer tests fine).

Some NULL pointer checks with or without associated error
reporting.

Some white space and comment formatting fixes.

Optimization: avoid unnecessary operations (unnecessary
memory allocation/deallocation and list copying).

Reverts 7821eb6f37 as such
trick is no longer needed, given that all memory leakages
have now been fixed.

This is the sixth version of this patch. Please do not use
the first version as it introduces a serious bug.

For reference, the original issue reported by the Cland
static analyzer is as follows:

support/fc_sort.c:494:6: warning: Potential leak of memory
pointed to by 'head'
            malloc(sizeof(file_context_bucket_t));

Signed-off-by: Guido Trentalancia <guido@trentalancia.com>
Acked-by: William Roberts <william.c.roberts@intel.com>
2017-10-04 19:29:47 -04:00
Luis A. Lozano cd20f0ba9f Avoid memory leak warning.
Using the LLVM static analyzer, we get a warning about leaked memory
pointed by bcurrent. Since the warning happens within "main" and we
don't care about deallocating the memory and just call "exit" which
gets rid of the warning.
2017-09-05 16:20:44 -07:00
Guido Trentalancia 89b53fafa9 fc_sort: avoid compiler warning/error
Fix a "-Werror=implicit-fallthrough" compiler warning/error on
the switch statement.

This third version (v3) fixes a bug introduced in the first
version and improves the style over the second version.

Signed-off-by: Guido Trentalancia <guido at trentalancia.com>
2017-06-07 19:13:28 -04:00
Rahul Chaudhry 0412d1ace4 fc_sort: cleanup warnings caught by clang tidy / static analyzer.
Value stored to 'i' is never read.
Variable 'j' is never used.
2016-10-19 13:29:20 -07:00
William Roberts cb4491c19e fc_sort: strip whitespace errors
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-01-07 08:41:32 -08:00
Nicolas Iooss aa3fa6d2fd fc_sort: make outfile argument optional
When working on fc_sort to try to understand why using /usr/s?bin/... file
contexts has been reported not to work properly [1], I found it frustrating not
to be able to do "tmp/fc_sort my_filecontexts.fc" and see the result printed on
the screen.  This patch implements this behavior by making optional the second
argument of fc_sort.

[1] commit 36e2216f8 of contrib repository,
http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-refpolicy.git;a=commit;h=36e2216f82192660d063012e69281f27ba20864b
2014-04-04 15:50:57 -04:00
Nicolas Iooss 572c617c91 fc_sort: initialize allocated memory to fix execution on an empty file
When running fc_sort on an empty context file, this program uses uninitialized
pointers when accessing to the elements of a list.  On my system, it goes in a
very long loop (maybe infinite) because uninitialized fields in malloc'ed
structures happen to contain valid pointers in the heap.

This patch fixes this bug by initializing ->next and ->data fields before they
may be read.
2014-04-04 15:47:36 -04:00
Nicolas Iooss eedc944a54 fc_sort: fix typos in comments 2014-04-04 15:47:36 -04:00
Chris PeBenito c87f945a5a Fix fc_sort.c warning uncovered by recent gcc
output_name in main was set to argv[2] but then argv[2] rather than
output_name was used later in the function.
2013-02-26 09:16:49 -05:00
Chris PeBenito 17de1b790b remove extra level of directory 2006-07-12 20:32:27 +00:00