diff mbox series

[v2,3/4] Avoiding freeing line prematurely. It's now only freed at the end of the function.

Message ID 20241011031937.92216-4-demeng@redhat.com
State New
Headers show
Series qemu-ga: Fix some potential issues find by coverity | expand

Commit Message

Dehan Meng Oct. 11, 2024, 3:19 a.m. UTC
Signed-off-by: Dehan Meng <demeng@redhat.com>
---
 qga/commands-linux.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Daniel P. Berrangé Oct. 14, 2024, 9:59 a.m. UTC | #1
The subject line is too long - put the second sentance on a line of
its own in the commit message, separated from the 1st line by a blank
line.

On Fri, Oct 11, 2024 at 11:19:36AM +0800, Dehan Meng wrote:
> Signed-off-by: Dehan Meng <demeng@redhat.com>
> ---
>  qga/commands-linux.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

> 
> diff --git a/qga/commands-linux.c b/qga/commands-linux.c
> index b905f33a57..4f0e38be81 100644
> --- a/qga/commands-linux.c
> +++ b/qga/commands-linux.c
> @@ -2137,8 +2137,7 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Error **errp)
>          is_ipv6 = (i == 1);
>          fp = fopen(routeFiles[i], "r");
>          if (fp == NULL) {
> -            error_setg_errno(errp, errno, "open(\"%s\")", routeFiles[i]);
> -            free(line);
> +            error_setg_errno(errp, errno, "open(\"%s\")", route_files[i]);
>              continue;
>          }
>  
> @@ -2218,9 +2217,8 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Error **errp)
>              QAPI_LIST_APPEND(tail, route);
>          }
>  
> -        free(line);
>          fclose(fp);
>      }
> -
> +    free(line);
>      return head;
>  }
> -- 
> 2.40.1
> 
> 

With regards,
Daniel
diff mbox series

Patch

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index b905f33a57..4f0e38be81 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -2137,8 +2137,7 @@  GuestNetworkRouteList *qmp_guest_network_get_route(Error **errp)
         is_ipv6 = (i == 1);
         fp = fopen(routeFiles[i], "r");
         if (fp == NULL) {
-            error_setg_errno(errp, errno, "open(\"%s\")", routeFiles[i]);
-            free(line);
+            error_setg_errno(errp, errno, "open(\"%s\")", route_files[i]);
             continue;
         }
 
@@ -2218,9 +2217,8 @@  GuestNetworkRouteList *qmp_guest_network_get_route(Error **errp)
             QAPI_LIST_APPEND(tail, route);
         }
 
-        free(line);
         fclose(fp);
     }
-
+    free(line);
     return head;
 }