[Spice-devel,server,v2,3/3] replay: do not use argv after g_option_context_parse

Submitted by Uri Lublin on March 6, 2016, 12:25 p.m.

Details

Message ID 1457267107-4660-4-git-send-email-uril@redhat.com
State New
Headers show
Series "replay: add count and skip" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

Uri Lublin March 6, 2016, 12:25 p.m.
Apparently, after using g_option_context_parse with G_OPTION_REMAINING
argv is modified and should not be used.
This patch uses "file" instead of "argv" and makes sure
file is freed later.
No free is called upon error - exit takes care of it.

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/tests/replay.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/tests/replay.c b/server/tests/replay.c
index 3642f2d..7e4659b 100644
--- a/server/tests/replay.c
+++ b/server/tests/replay.c
@@ -358,12 +358,12 @@  int main(int argc, char **argv)
     } else {
         fd = fopen(file[0], "r");
     }
-    g_strfreev(file);
-    file = NULL;
     if (fd == NULL) {
-        g_printerr("error opening %s\n", argv[1]);
-        return 1;
+        g_printerr("error opening %s\n", file[0]);
+        exit(1);
     }
+    g_strfreev(file);
+    file = NULL;
     if (fcntl(fileno(fd), FD_CLOEXEC) < 0) {
         perror("fcntl failed");
         exit(1);

Comments

> 
> Apparently, after using g_option_context_parse with G_OPTION_REMAINING
> argv is modified and should not be used.
> This patch uses "file" instead of "argv" and makes sure
> file is freed later.
> No free is called upon error - exit takes care of it.
> 
> Signed-off-by: Uri Lublin <uril@redhat.com>
> Acked-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  server/tests/replay.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/server/tests/replay.c b/server/tests/replay.c
> index 3642f2d..7e4659b 100644
> --- a/server/tests/replay.c
> +++ b/server/tests/replay.c
> @@ -358,12 +358,12 @@ int main(int argc, char **argv)
>      } else {
>          fd = fopen(file[0], "r");
>      }
> -    g_strfreev(file);
> -    file = NULL;
>      if (fd == NULL) {
> -        g_printerr("error opening %s\n", argv[1]);
> -        return 1;
> +        g_printerr("error opening %s\n", file[0]);
> +        exit(1);
>      }
> +    g_strfreev(file);
> +    file = NULL;
>      if (fcntl(fileno(fd), FD_CLOEXEC) < 0) {
>          perror("fcntl failed");
>          exit(1);

Merged

Frediano