Merge pull request #2041 from signalwire/coverity_13042023_mod_java
[mod_java] Coverity CID 1320752 (Resource leak)
This commit is contained in:
commit
371d3c6164
|
@ -194,71 +194,72 @@ static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount,
|
||||||
char *derr = NULL;
|
char *derr = NULL;
|
||||||
|
|
||||||
xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
|
xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
|
||||||
if (xml)
|
if (xml) {
|
||||||
{
|
|
||||||
switch_xml_t javavm;
|
switch_xml_t javavm;
|
||||||
switch_xml_t options;
|
switch_xml_t options;
|
||||||
switch_xml_t startup;
|
switch_xml_t startup;
|
||||||
switch_xml_t shutdown;
|
switch_xml_t shutdown;
|
||||||
|
|
||||||
javavm = switch_xml_child(cfg, "javavm");
|
javavm = switch_xml_child(cfg, "javavm");
|
||||||
if (javavm != NULL)
|
if (javavm != NULL) {
|
||||||
{
|
|
||||||
const char *path = switch_xml_attr_soft(javavm, "path");
|
const char *path = switch_xml_attr_soft(javavm, "path");
|
||||||
if (path != NULL)
|
|
||||||
{
|
if (path != NULL) {
|
||||||
javaVMHandle = switch_dso_open(path, 0, &derr);
|
javaVMHandle = switch_dso_open(path, 0, &derr);
|
||||||
if (derr || !javaVMHandle) {
|
if (derr || !javaVMHandle) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
|
||||||
|
switch_safe_free(derr);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
options = switch_xml_child(cfg, "options");
|
options = switch_xml_child(cfg, "options");
|
||||||
if (options != NULL)
|
if (options != NULL) {
|
||||||
{
|
|
||||||
switch_xml_t option;
|
switch_xml_t option;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
*optionCount = 0;
|
*optionCount = 0;
|
||||||
for (option = switch_xml_child(options, "option"); option; option = option->next)
|
|
||||||
{
|
for (option = switch_xml_child(options, "option"); option; option = option->next) {
|
||||||
const char *value = switch_xml_attr_soft(option, "value");
|
const char *value = switch_xml_attr_soft(option, "value");
|
||||||
if (value != NULL)
|
|
||||||
|
if (value != NULL) {
|
||||||
++*optionCount;
|
++*optionCount;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*optionCount += 1;
|
*optionCount += 1;
|
||||||
*javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
|
*javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
|
||||||
if (*javaOptions == NULL)
|
if (*javaOptions == NULL) {
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
for (option = switch_xml_child(options, "option"); option; option = option->next)
|
|
||||||
{
|
for (option = switch_xml_child(options, "option"); option; option = option->next) {
|
||||||
const char *value = switch_xml_attr_soft(option, "value");
|
const char *value = switch_xml_attr_soft(option, "value");
|
||||||
if (value == NULL)
|
|
||||||
|
if (value == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
(*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
|
(*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
|
||||||
if ((*javaOptions)[i].optionString == NULL)
|
if ((*javaOptions)[i].optionString == NULL) {
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*javaOptions)[i].optionString = switch_core_sprintf(memoryPool, "-Djava.library.path=%s", SWITCH_GLOBAL_dirs.mod_dir);
|
(*javaOptions)[i].optionString = switch_core_sprintf(memoryPool, "-Djava.library.path=%s", SWITCH_GLOBAL_dirs.mod_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +275,7 @@ static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount,
|
||||||
vmControl->startup.method = switch_xml_attr_soft(startup, "method");
|
vmControl->startup.method = switch_xml_attr_soft(startup, "method");
|
||||||
vmControl->startup.arg = switch_xml_attr_soft(startup, "arg");
|
vmControl->startup.arg = switch_xml_attr_soft(startup, "arg");
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown = switch_xml_child(cfg, "shutdown");
|
shutdown = switch_xml_child(cfg, "shutdown");
|
||||||
if (shutdown != NULL) {
|
if (shutdown != NULL) {
|
||||||
vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class");
|
vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class");
|
||||||
|
@ -283,12 +285,11 @@ static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount,
|
||||||
|
|
||||||
close:
|
close:
|
||||||
switch_xml_free(xml);
|
switch_xml_free(xml);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
|
||||||
status = SWITCH_STATUS_FALSE;
|
status = SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue