[Spice-devel] [PATCH spice-server v2 2/3] test-gst: Remove options parsing leaks

Frediano Ziglio fziglio at redhat.com
Tue Sep 12 07:25:57 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 | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Changes since v1:
- improved commit message;
- make code more clear to read.

diff --git a/server/tests/test-gst.c b/server/tests/test-gst.c
index 40f738d78..a78432eaa 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,20 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
-    const EncoderInfo *encoder = get_encoder_info(encoder_name);
+    const EncoderInfo *encoder =
+        encoder_name ? get_encoder_info(encoder_name) : encoder_info_mjpeg;
     if (!encoder) {
         g_printerr("Encoder name unsupported: %s\n", encoder_name);
         exit(1);
     }
 
-    bitmap_format = get_bitmap_format(image_format);
+    bitmap_format = image_format ? get_bitmap_format(image_format) : SPICE_BITMAP_FMT_32BIT;
     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 +434,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