python/audit2allow: close file stream on error
PATCH 1/1 python/audit2allow: close file stream on error
sepolgen-ifgen-attr-helper.c: In function ‘load_policy’:
sepolgen-ifgen-attr-helper.c:196:17: warning: leak of FILE ‘fp’ [CWE-775] [-Wanalyzer-file-leak]
196 | fprintf(stderr, "Out of memory!\n");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- python/audit2allow/sepolgen-ifgen-attr-helper.c | 3 +++ 1 file changed, 3 insertions(+)
python/audit2allow/sepolgen-ifgen-attr-helper.c +3 -0
@@ -194,12 +194,14 @@ static policydb_t *load_policy(const char *filename) policydb =malloc (sizeof (policydb_t));if (policydb ==NULL ) {fprintf (stderr,"Out of memory!\n" ); +fclose (fp);return NULL ; }if (policydb_init (policydb)) {fprintf (stderr,"Out of memory!\n" );free (policydb); +fclose (fp);return NULL ; }
@@ -208,6 +210,7 @@ static policydb_t *load_policy(const char *filename)fprintf (stderr,"error(s) encountered while parsing configuration\n" );free (policydb); +fclose (fp);return NULL ; }
Signature · 1 line
2.36.1
Quoted 7 lines · Christian Göttsche
sepolgen-ifgen-attr-helper.c: In function ‘load_policy’:
sepolgen-ifgen-attr-helper.c:196:17: warning: leak of FILE ‘fp’ [CWE-775] [-Wanalyzer-file-leak]
196 |fprintf(stderr, "Out of memory!\n");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Signed-off-by Christian Göttsche <[email protected]>
Quoted 34 lines
--- python/audit2allow/sepolgen-ifgen-attr-helper.c | 3 +++ 1 file changed, 3 insertions(+)python/audit2allow/sepolgen-ifgen-attr-helper.c +3
-1@@ -194,12 +194,14 @@ static policydb_t *load_policy(const char *filename) policydb =malloc (sizeof (policydb_t));if (policydb ==NULL ) {fprintf (stderr,"Out of memory!\n" ); +fclose (fp);return NULL ; }if (policydb_init (policydb)) {fprintf (stderr,"Out of memory!\n" );free (policydb); +fclose (fp);return NULL ; }@@ -208,6 +210,7 @@ static policydb_t *load_policy(const char *filename)fprintf (stderr,"error(s) encountered while parsing configuration\n" );free (policydb); +fclose (fp);return NULL ; } --2.36.1
Quoted 4 lines · James Carter
Quoted 1 line · Christian Göttsche
Quoted 9 lines
Quoted 6 lines
sepolgen-ifgen-attr-helper.c: In function ‘load_policy’:
sepolgen-ifgen-attr-helper.c:196:17: warning: leak of FILE ‘fp’ [CWE-775] [-Wanalyzer-file-leak]
196 |fprintf(stderr, "Out of memory!\n");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Signed-off-by Christian Göttsche <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 34 lines
Quoted 34 lines
--- python/audit2allow/sepolgen-ifgen-attr-helper.c | 3 +++ 1 file changed, 3 insertions(+)python/audit2allow/sepolgen-ifgen-attr-helper.c +3
-1@@ -194,12 +194,14 @@ static policydb_t *load_policy(const char *filename) policydb =malloc (sizeof (policydb_t));if (policydb ==NULL ) {fprintf (stderr,"Out of memory!\n" ); +fclose (fp);return NULL ; }if (policydb_init (policydb)) {fprintf (stderr,"Out of memory!\n" );free (policydb); +fclose (fp);return NULL ; }@@ -208,6 +210,7 @@ static policydb_t *load_policy(const char *filename)fprintf (stderr,"error(s) encountered while parsing configuration\n" );free (policydb); +fclose (fp);return NULL ; } --2.36.1