]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[core] Coverity fixes
authorJakub Karolczyk <jakub.karolczyk@signalwire.com>
Fri, 31 Mar 2023 21:07:59 +0000 (22:07 +0100)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2023 21:07:59 +0000 (00:07 +0300)
* [core] Coverity CID 1468218 (Resource leak)

* [core] Coverity CID 1468214 (Resource leak)

* [core] Coverity CID 1294472 (Resource leak)

* [core] Coverity CID 1294470 (Resource leak)

* [core] Coverity CID 1500361 (Resource leak)

* [core] Coverity CID 1500308 (Resource leak)

* [core] Coverity CID 1500278 (Resource leak)

---------

Co-authored-by: Andrey Volk <andywolk@gmail.com>
src/include/switch_core_video.h
src/mod/applications/mod_cv/mod_cv.cpp
src/mod/applications/mod_video_filter/mod_video_filter.c
src/mod/formats/mod_imagick/mod_imagick.c
src/switch_core_sqldb.c
src/switch_core_video.c
src/switch_event.c
src/switch_xml.c

index 1af0dec7ac05c867577a4f5e50af6e130faacd21..f65c322d30b164d2bac8513fb6eff72685bd827d 100644 (file)
@@ -448,7 +448,7 @@ SWITCH_DECLARE(switch_status_t) switch_img_to_raw(switch_image_t *src, void *des
 * \param[in]    width     The raw data width
 * \param[in]    height    The raw data height
 */
-SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void *src, switch_img_fmt_t fmt, int width, int height);
+SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t** destP, void *src, switch_img_fmt_t fmt, int width, int height);
 SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, switch_bool_t full, const char *text);
 
 SWITCH_DECLARE(switch_image_t *) switch_img_read_file(const char* file_name);
index 800452dd9abd54da6ae5790071be978e46a4adf3..de39943b4b733155a6da1e7b0d0ec0beabd7f625 100644 (file)
@@ -854,7 +854,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
     }
 
     if (context->rawImage && (context->debug || !context->overlay_count)) {
-        switch_img_from_raw(frame->img, (uint8_t *)context->rawImage->imageData, SWITCH_IMG_FMT_RGB24, context->rawImage->width, context->rawImage->height);
+        switch_img_from_raw(&frame->img, (uint8_t *)context->rawImage->imageData, SWITCH_IMG_FMT_RGB24, context->rawImage->width, context->rawImage->height);
     }
 
     int abs = 0;
index 7cf1f1dd0f6d084a68e437b51036afb346d75cb6..605559fdbb8202c1fe96257272d889be1fda6bf4 100644 (file)
@@ -645,7 +645,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
        }
 
 
-       switch_img_from_raw(frame->img, patch_data, SWITCH_IMG_FMT_ARGB, frame->img->d_w, frame->img->d_h);
+       switch_img_from_raw(&frame->img, patch_data, SWITCH_IMG_FMT_ARGB, frame->img->d_w, frame->img->d_h);
 
        switch_img_free(&img);
 
index ce789637cf2b19fcbcad63b2807646d18c01bbae..beb60387bf4351ceecdd19747c1b3b93be3b2c79 100644 (file)
@@ -387,7 +387,7 @@ static switch_status_t read_page(pdf_file_context_t *context)
                        return SWITCH_STATUS_FALSE;
                }
 
-               switch_img_from_raw(context->img, storage, SWITCH_IMG_FMT_BGR24, w, h);
+               switch_img_from_raw(&context->img, storage, SWITCH_IMG_FMT_BGR24, w, h);
                free(storage);
        } else {
                switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, image->columns, image->rows, 0);
index 702ee6a79c3656e03411ff3ead8468df8cc7bc9a..5a75aeb573daef9c3ea230fd2ac43f2e1829e7af 100644 (file)
@@ -3181,6 +3181,8 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
 
        if (!(ep = switch_loadable_module_get_endpoint_interface(argv[0]))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "EP ERROR\n");
+               switch_xml_free(xml);
+
                return 0;
        }
 
index 0d377f9c3e4669df04f65dc53219cea75febf6e4..dad3181c2a3ded7a90c190a11b0a4153d9411234 100644 (file)
@@ -3521,11 +3521,18 @@ SWITCH_DECLARE(switch_status_t) switch_img_to_raw(switch_image_t *src, void *des
 #endif
 }
 
-SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void *src, switch_img_fmt_t fmt, int width, int height)
+SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t **destP, void *src, switch_img_fmt_t fmt, int width, int height)
 {
 #ifdef SWITCH_HAVE_YUV
        uint32_t fourcc;
        int ret = -1;
+       switch_image_t *dest = NULL;
+
+       if (!destP) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       dest = *destP;
 
        fourcc = switch_img_fmt2fourcc(fmt);
 
@@ -3574,6 +3581,8 @@ SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void *
                                        0, fourcc);
        }
 
+       *destP = dest;
+
        return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
 #else
        return SWITCH_STATUS_FALSE;
@@ -3586,10 +3595,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_ima
        switch_image_t *dest = NULL;
        int ret = 0;
 
-       if (destP) {
-               dest = *destP;
+       if (!destP) {
+               return SWITCH_STATUS_FALSE;
        }
 
+       dest = *destP;
+
        switch_assert(width > 0);
        switch_assert(height > 0);
        
@@ -3615,15 +3626,13 @@ SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_ima
                                kFilterBox);
        }
 
+       *destP = dest;
+
        if (ret != 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scaling Error: ret: %d\n", ret);
                return SWITCH_STATUS_FALSE;
        }
 
-       if (destP) {
-               *destP = dest;
-       }
-
        return SWITCH_STATUS_SUCCESS;
 #else
        return SWITCH_STATUS_FALSE;
@@ -3637,10 +3646,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_mirror(switch_image_t *src, switch_im
        switch_image_t *dest = NULL;
        int ret = 0;
 
-       if (destP) {
-               dest = *destP;
+       if (!destP) {
+               return SWITCH_STATUS_FALSE;
        }
 
+       dest = *destP;
+
        if (dest && src->fmt != dest->fmt) switch_img_free(&dest);
 
        if (!dest) dest = switch_img_alloc(NULL, src->fmt, src->d_w, src->d_h, 1);
@@ -3660,15 +3671,13 @@ SWITCH_DECLARE(switch_status_t) switch_img_mirror(switch_image_t *src, switch_im
                
        }
 
+       *destP = dest;
+
        if (ret != 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Mirror Error: ret: %d\n", ret);
                return SWITCH_STATUS_FALSE;
        }
 
-       if (destP) {
-               *destP = dest;
-       }
-
        return SWITCH_STATUS_SUCCESS;
 #else
        return SWITCH_STATUS_FALSE;
index 843469bd72b5dd56d5b0a98efe95b24fa608fb96..be49f2fc14579b575f430f5caa50f0854ce7ea44 100644 (file)
@@ -1909,6 +1909,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
                data = (char *) malloc(2048);
                if (!data) {
                        va_end(ap);
+                       switch_xml_free(xml);
+
                        return NULL;
                }
                ret = vsnprintf(data, 2048, fmt, ap);
@@ -1918,6 +1920,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
 #ifndef HAVE_VASPRINTF
                        free(data);
 #endif
+                       switch_xml_free(xml);
+
                        return NULL;
                }
        }
index c43a530252e5c5f6ecfa2b1520c5bf66e5bffb5a..80b75539073d3275dc706553036e80d7d6e69c23 100644 (file)
@@ -1638,11 +1638,25 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
 
        if ((fd = open(file, O_RDONLY, 0)) > -1) {
                fstat(fd, &st);
-               if (!st.st_size) goto error;
+               if (!st.st_size) {
+                       close(fd);
+                       goto error;
+               }
+
                m = switch_must_malloc(st.st_size);
 
-               if (!(0<(l = read(fd, m, st.st_size)))) goto error;
-               if (!(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) goto error;
+               if (!(0 < (l = read(fd, m, st.st_size)))) {
+                       free(m);
+                       close(fd);
+                       goto error;
+               }
+
+               if (!(root = (switch_xml_root_t)switch_xml_parse_str((char*)m, l))) {
+                       free(m);
+                       close(fd);
+                       goto error;
+               }
+
                root->dynamic = 1;
                close(fd);
                return &root->xml;