Skip to contentSkip to conversation

python/audit2allow: close file stream on error

PATCH In review Christian Göttsche 2 participants 3 messages May 20, 2022 – Jun 15, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

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
index 6f3ba962..5e6cffc1 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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
index 6f3ba962..5e6cffc1 100644
@@ -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

#2 lore raw
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");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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
index 6f3ba962..5e6cffc1 100644
@@ -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