diff mbox series

[1/1] /net/tap.c: Fix a memory leak

Message ID 20201122044426.13454-1-ruc_gongyuanjun@163.com
State New
Headers show
Series [1/1] /net/tap.c: Fix a memory leak | expand

Commit Message

ruc_gongyuanjun@163.com Nov. 22, 2020, 4:44 a.m. UTC
From: yuanjungong <ruc_gongyuanjun@163.com>

Close fd before returning.

Buglink: https://bugs.launchpad.net/qemu/+bug/1904486
Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com>
---
 net/tap.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Peter Maydell Nov. 22, 2020, 11:39 a.m. UTC | #1
On Sun, 22 Nov 2020 at 11:07, <ruc_gongyuanjun@163.com> wrote:
>
> From: yuanjungong <ruc_gongyuanjun@163.com>
>
> Close fd before returning.
>
> Buglink: https://bugs.launchpad.net/qemu/+bug/1904486
> Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com>
> ---
>  net/tap.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/net/tap.c b/net/tap.c
> index c46ff66..fe95fa7 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -817,6 +817,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>          if (ret < 0) {
>              error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
>                               name, fd);
> +            close(fd);
>              return -1;
>          }
>
> @@ -831,6 +832,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>                           vhostfdname, vnet_hdr, fd, &err);
>          if (err) {
>              error_propagate(errp, err);
> +            close(fd);
>              return -1;
>          }
>      } else if (tap->has_fds) {
> --
> 2.17.1

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Jason Wang Nov. 23, 2020, 2:51 a.m. UTC | #2
On 2020/11/22 下午7:39, Peter Maydell wrote:
> On Sun, 22 Nov 2020 at 11:07, <ruc_gongyuanjun@163.com> wrote:
>> From: yuanjungong <ruc_gongyuanjun@163.com>
>>
>> Close fd before returning.
>>
>> Buglink: https://bugs.launchpad.net/qemu/+bug/1904486
>> Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com>
>> ---
>>   net/tap.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/net/tap.c b/net/tap.c
>> index c46ff66..fe95fa7 100644
>> --- a/net/tap.c
>> +++ b/net/tap.c
>> @@ -817,6 +817,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>>           if (ret < 0) {
>>               error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
>>                                name, fd);
>> +            close(fd);
>>               return -1;
>>           }
>>
>> @@ -831,6 +832,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
>>                            vhostfdname, vnet_hdr, fd, &err);
>>           if (err) {
>>               error_propagate(errp, err);
>> +            close(fd);
>>               return -1;
>>           }
>>       } else if (tap->has_fds) {
>> --
>> 2.17.1
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> thanks
> -- PMM


Applied.

Thanks


>
diff mbox series

Patch

diff --git a/net/tap.c b/net/tap.c
index c46ff66..fe95fa7 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -817,6 +817,7 @@  int net_init_tap(const Netdev *netdev, const char *name,
         if (ret < 0) {
             error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
                              name, fd);
+            close(fd);
             return -1;
         }
 
@@ -831,6 +832,7 @@  int net_init_tap(const Netdev *netdev, const char *name,
                          vhostfdname, vnet_hdr, fd, &err);
         if (err) {
             error_propagate(errp, err);
+            close(fd);
             return -1;
         }
     } else if (tap->has_fds) {