Skip to content

Commit a9d3b23

Browse files
committed
tests: fix a memory leak
2021-10-12T12:04:30.8634717Z ==13254==ERROR: LeakSanitizer: detected memory leaks 2021-10-12T12:04:30.8635500Z 2021-10-12T12:04:30.8636953Z Direct leak of 823 byte(s) in 1 object(s) allocated from: 2021-10-12T12:04:30.8638969Z #0 0x7ff702a82bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8) 2021-10-12T12:04:30.8640457Z #1 0x559506e3b99c in write_test_policy_from_file /home/runner/work/selinux/selinux/libsemanage/tests/utilities.c:112 2021-10-12T12:04:30.8642027Z #2 0x559506e1ddba in iface_test_init /home/runner/work/selinux/selinux/libsemanage/tests/test_iface.c:73 2021-10-12T12:04:30.8643708Z #3 0x7ff702769e0d (/lib/x86_64-linux-gnu/libcunit.so.1+0x3e0d) Signed-off-by: Evgeny Vereshchagin <[email protected]>
1 parent 48900e7 commit a9d3b23

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libsemanage/tests/utilities.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ int write_test_policy_from_file(const char *filename) {
9999
char *buf = NULL;
100100
size_t len = 0;
101101
FILE *fptr = fopen(filename, "rb");
102+
int ret = -1;
102103

103104
if (!fptr) {
104105
perror("fopen");
105-
return -1;
106+
return ret;
106107
}
107108

108109
fseek(fptr, 0, SEEK_END);
@@ -114,13 +115,15 @@ int write_test_policy_from_file(const char *filename) {
114115
if (!buf) {
115116
perror("malloc");
116117
fclose(fptr);
117-
return -1;
118+
return ret;
118119
}
119120

120121
fread(buf, len, 1, fptr);
121122
fclose(fptr);
122123

123-
return write_test_policy(buf, len);
124+
ret = write_test_policy(buf, len);
125+
free(buf);
126+
return ret;
124127
}
125128

126129
int write_test_policy_src(unsigned char *data, unsigned int data_len) {

0 commit comments

Comments
 (0)