[Spice-devel] [PATCH spice-server v3] test-gst: Remove options parsing leaks

Frediano Ziglio fziglio at redhat.com
Tue Sep 12 09:45:08 UTC 2017


Command line options are not freed at the end of the program.
These are detected as leaks by leak detector tools like address sanitizer.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/tests/test-gst.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

Changes since v2:
- update syntax

diff --git a/server/tests/test-gst.c b/server/tests/test-gst.c
index 40f738d78..302158a27 100644
--- a/server/tests/test-gst.c
+++ b/server/tests/test-gst.c
@@ -296,6 +296,7 @@ output_frames(GstSample *sample, void *param)
 static const EncoderInfo encoder_infos[] = {
     { "mjpeg", mjpeg_encoder_new, SPICE_VIDEO_CODEC_TYPE_MJPEG,
       "caps=image/jpeg", "jpegdec" },
+#define encoder_info_mjpeg (&encoder_infos[0])
     { "gstreamer:mjpeg", gstreamer_encoder_new, SPICE_VIDEO_CODEC_TYPE_MJPEG,
       "caps=image/jpeg", "jpegdec" },
     { "gstreamer:vp8",   gstreamer_encoder_new, SPICE_VIDEO_CODEC_TYPE_VP8,
@@ -314,11 +315,11 @@ static const EncoderInfo encoder_infos[] = {
 int main(int argc, char *argv[])
 {
     gchar *input_pipeline_desc = NULL;
-    const gchar *image_format = "32BIT";
-    const gchar *encoder_name = "mjpeg";
+    gchar *image_format = NULL;
+    gchar *encoder_name = NULL;
     gchar *file_report_name = NULL;
     gboolean use_hw_encoder = FALSE; // TODO use
-    const gchar *clipping = "(0,0)x(100%,100%)";
+    gchar *clipping = NULL;
 
     // - input pipeline
     // - top/down
@@ -368,19 +369,24 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
-    const EncoderInfo *encoder = get_encoder_info(encoder_name);
-    if (!encoder) {
-        g_printerr("Encoder name unsupported: %s\n", encoder_name);
-        exit(1);
+    const EncoderInfo *encoder = encoder_info_mjpeg;
+    if (encoder_name != NULL) {
+        encoder = get_encoder_info(encoder_name);
+        if (!encoder) {
+            g_printerr("Encoder name unsupported: %s\n", encoder_name);
+            exit(1);
+        }
     }
 
-    bitmap_format = get_bitmap_format(image_format);
-    if (bitmap_format == SPICE_BITMAP_FMT_INVALID) {
-        g_printerr("Invalid image format: %s\n", image_format);
-        exit(1);
+    if (image_format != NULL) {
+        bitmap_format = get_bitmap_format(image_format);
+        if (bitmap_format == SPICE_BITMAP_FMT_INVALID) {
+            g_printerr("Invalid image format: %s\n", image_format);
+            exit(1);
+        }
     }
 
-    parse_clipping(clipping);
+    parse_clipping(clipping ? clipping : "(0,0)x(100%,100%)");
 
     if (minimum_psnr < 0) {
         g_printerr("Invalid PSNR specified %f\n", minimum_psnr);
@@ -432,6 +438,12 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
+    g_free(encoder_name);
+    g_free(image_format);
+    g_free(input_pipeline_desc);
+    g_free(clipping);
+    g_option_context_free(context);
+
     return 0;
 }
 
-- 
2.13.5



More information about the Spice-devel mailing list