[Core] Fix possible file descriptor and a memory leak in switch_xml_parse_file_simple().

This commit is contained in:
Andrey Volk 2022-12-26 13:27:03 +03:00
parent f71a56022a
commit 67a7ffeb51
1 changed files with 6 additions and 1 deletions

View File

@ -1633,7 +1633,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
int fd = -1; int fd = -1;
struct stat st; struct stat st;
switch_ssize_t l; switch_ssize_t l;
void *m; void *m = NULL;
switch_xml_root_t root; switch_xml_root_t root;
if ((fd = open(file, O_RDONLY, 0)) > -1) { if ((fd = open(file, O_RDONLY, 0)) > -1) {
@ -1650,6 +1650,11 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
error: error:
switch_safe_free(m);
if (fd > -1) {
close(fd);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing File [%s]\n", file); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing File [%s]\n", file);
return NULL; return NULL;