2010-11-05 05:44:42

by Jovi Zhang

[permalink] [raw]
Subject: [PATCH] kdb: fix memory leak

fix memory leak in kdb_main.c

Signed-off-by: jovi zhang <[email protected]>
kernel/debug/kdb/kdb_main.c |   13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 37755d6..3ab3fee 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -2361,7 +2361,7 @@ static int kdb_pid(int argc, const char **argv)
 */
static int kdb_ll(int argc, const char **argv)
{
-       int diag;
+       int diag = 0;
       unsigned long addr;
       long offset = 0;
       unsigned long va;
@@ -2400,20 +2400,21 @@ static int kdb_ll(int argc, const char **argv)
               char buf[80];

               if (KDB_FLAG(CMD_INTERRUPT))
-                       return 0;
+                       goto out;

               sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va);
               diag = kdb_parse(buf);
               if (diag)
-                       return diag;
+                       goto out;

               addr = va + linkoffset;
               if (kdb_getword(&va, addr, sizeof(va)))
-                       return 0;
+                       goto out;
       }
-       kfree(command);

-       return 0;
+out:
+       kfree(command);
+       return diag;
}

static int kdb_kgdb(int argc, const char **argv)
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?


2010-11-05 07:46:29

by Dongdong Deng

[permalink] [raw]
Subject: Re: [PATCH] kdb: fix memory leak

On Fri, Nov 5, 2010 at 1:44 PM, jovi zhang <[email protected]> wrote:
> fix memory leak in kdb_main.c
>
> Signed-off-by: jovi zhang <[email protected]>
> kernel/debug/kdb/kdb_main.c |   13 +++++++------
> 1 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
> index 37755d6..3ab3fee 100644
> --- a/kernel/debug/kdb/kdb_main.c
> +++ b/kernel/debug/kdb/kdb_main.c
> @@ -2361,7 +2361,7 @@ static int kdb_pid(int argc, const char **argv)
>  */
> static int kdb_ll(int argc, const char **argv)
> {
> -       int diag;
> +       int diag = 0;
>        unsigned long addr;
>        long offset = 0;
>        unsigned long va;
> @@ -2400,20 +2400,21 @@ static int kdb_ll(int argc, const char **argv)
>                char buf[80];
>
>                if (KDB_FLAG(CMD_INTERRUPT))
> -                       return 0;
> +                       goto out;
>
>                sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va);
>                diag = kdb_parse(buf);
>                if (diag)
> -                       return diag;
> +                       goto out;
>
>                addr = va + linkoffset;
>                if (kdb_getword(&va, addr, sizeof(va)))
> -                       return 0;
> +                       goto out;
>        }
> -       kfree(command);
>
> -       return 0;
> +out:
> +       kfree(command);
> +       return diag;
> }
>
> static int kdb_kgdb(int argc, const char **argv)
>


It is ok for me. :-)

Dongdong
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?