]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_java] Coverity CID 1320752 (Resource leak) 2041/head
authorJakub Karolczyk <jakub.karolczyk@signalwire.com>
Thu, 13 Apr 2023 12:58:08 +0000 (13:58 +0100)
committerJakub Karolczyk <jakub.karolczyk@signalwire.com>
Fri, 14 Apr 2023 16:41:33 +0000 (17:41 +0100)
src/mod/languages/mod_java/modjava.c

index 899fee2b60085441fb20ecfa72dd79eaca4a92ee..9c38bdb70ffad74228bde01051688e23115774a2 100644 (file)
@@ -189,107 +189,108 @@ SWITCH_STANDARD_APP(java_function)
 
 static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount, vm_control_t * vmControl)
 {
-    switch_xml_t cfg, xml;
-    switch_status_t status = SWITCH_STATUS_SUCCESS;
+       switch_xml_t cfg, xml;
+       switch_status_t status = SWITCH_STATUS_SUCCESS;
        char *derr = NULL;
 
-    xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
-    if (xml)
-    {
-        switch_xml_t javavm;
-        switch_xml_t options;
-        switch_xml_t startup;
-        switch_xml_t shutdown;
-
-        javavm = switch_xml_child(cfg, "javavm");
-        if (javavm != NULL)
-        {
-            const char *path = switch_xml_attr_soft(javavm, "path");
-            if (path != NULL)
-            {
+       xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
+       if (xml) {
+               switch_xml_t javavm;
+               switch_xml_t options;
+               switch_xml_t startup;
+               switch_xml_t shutdown;
+
+               javavm = switch_xml_child(cfg, "javavm");
+               if (javavm != NULL) {
+                       const char *path = switch_xml_attr_soft(javavm, "path");
+
+                       if (path != NULL) {
                                javaVMHandle = switch_dso_open(path, 0, &derr);
                                if (derr || !javaVMHandle) {
                     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
+                                       switch_safe_free(derr);
                                }
-            }
-            else
-            {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
-                status = SWITCH_STATUS_FALSE;
-            }
-        }
-        else
-        {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
-            status = SWITCH_STATUS_FALSE;
-            goto close;
-        }
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
+                               status = SWITCH_STATUS_FALSE;
+                       }
+               } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
+                               status = SWITCH_STATUS_FALSE;
+                               goto close;
+               }
+
+               options = switch_xml_child(cfg, "options");
+               if (options != NULL) {
+                       switch_xml_t option;
+                       int i = 0;
+
+                       *optionCount = 0;
+
+                       for (option = switch_xml_child(options, "option"); option; option = option->next) {
+                               const char *value = switch_xml_attr_soft(option, "value");
+
+                               if (value != NULL) {
+                                       ++*optionCount;
+                               }
+                       }
+
+                       *optionCount += 1;
+                       *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
+                       if (*javaOptions == NULL) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
+                               status = SWITCH_STATUS_FALSE;
+                               goto close;
+                       }
+
+                       for (option = switch_xml_child(options, "option"); option; option = option->next) {
+                               const char *value = switch_xml_attr_soft(option, "value");
+
+                               if (value == NULL) {
+                                       continue;
+                               }
+
+                               (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
+                               if ((*javaOptions)[i].optionString == NULL) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
+                                       status = SWITCH_STATUS_FALSE;
+                                       goto close;
+                               }
+
+                               ++i;
+                       }
 
-        options = switch_xml_child(cfg, "options");
-        if (options != NULL)
-        {
-            switch_xml_t option;
-            int i = 0;
-            *optionCount = 0;
-            for (option = switch_xml_child(options, "option"); option; option = option->next)
-            {
-                const char *value = switch_xml_attr_soft(option, "value");
-                if (value != NULL)
-                    ++*optionCount;
-            }
-            *optionCount += 1;
-            *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
-            if (*javaOptions == NULL)
-            {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
-                status = SWITCH_STATUS_FALSE;
-                goto close;
-            }
-            for (option = switch_xml_child(options, "option"); option; option = option->next)
-            {
-                const char *value = switch_xml_attr_soft(option, "value");
-                if (value == NULL)
-                    continue;
-                (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
-                if ((*javaOptions)[i].optionString == NULL)
-                {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
-                    status = SWITCH_STATUS_FALSE;
-                    goto close;
-                }
-                ++i;
-            }
                        (*javaOptions)[i].optionString = switch_core_sprintf(memoryPool, "-Djava.library.path=%s", SWITCH_GLOBAL_dirs.mod_dir);
-        }
+               }
 
-       /*
-       <startup class="net/cog/fs/system/Control" method="startup" arg="start up arg"/>
-       <shutdown class="net/cog/fs/system/Control" method="shutdown" arg="shutdown arg"/>
-       */
-
-        memset(vmControl, 0, sizeof(struct vm_control));
-        startup = switch_xml_child(cfg, "startup");
-        if (startup != NULL) {
-            vmControl->startup.class = switch_xml_attr_soft(startup, "class");
-            vmControl->startup.method = switch_xml_attr_soft(startup, "method");
-            vmControl->startup.arg = switch_xml_attr_soft(startup, "arg");
-        }
-        shutdown = switch_xml_child(cfg, "shutdown");
-        if (shutdown != NULL) {
-            vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class");
-            vmControl->shutdown.method = switch_xml_attr_soft(shutdown, "method");
-            vmControl->shutdown.arg = switch_xml_attr_soft(shutdown, "arg");
-        }
+               /*
+               <startup class="net/cog/fs/system/Control" method="startup" arg="start up arg"/>
+               <shutdown class="net/cog/fs/system/Control" method="shutdown" arg="shutdown arg"/>
+               */
+
+               memset(vmControl, 0, sizeof(struct vm_control));
+               startup = switch_xml_child(cfg, "startup");
+               if (startup != NULL) {
+                       vmControl->startup.class = switch_xml_attr_soft(startup, "class");
+                       vmControl->startup.method = switch_xml_attr_soft(startup, "method");
+                       vmControl->startup.arg = switch_xml_attr_soft(startup, "arg");
+               }
 
-    close:
-        switch_xml_free(xml);
-    }
-    else
-    {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
-        status = SWITCH_STATUS_FALSE;
-    }
-    return status;
+               shutdown = switch_xml_child(cfg, "shutdown");
+               if (shutdown != NULL) {
+                       vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class");
+                       vmControl->shutdown.method = switch_xml_attr_soft(shutdown, "method");
+                       vmControl->shutdown.arg = switch_xml_attr_soft(shutdown, "arg");
+               }
+
+         close:
+               switch_xml_free(xml);
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
+               status = SWITCH_STATUS_FALSE;
+       }
+
+       return status;
 }
 
 static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm_control_t * vmControl)