[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: bug-report: ash: fix a memory leak
From:       Rich Felker <dalias () libc ! org>
Date:       2014-12-24 5:53:55
Message-ID: 20141224055355.GK4574 () brightrain ! aerifal ! cx
[Download RAW message or body]

On Wed, Dec 24, 2014 at 10:32:19AM +0800, yhu2 wrote:
> The script which triggers the leak:
> 
> while true
>   do
>     while true
>       do
>         break;
>     done</dev/null
> done
> 
> someone had fixed this bug, the commit is:
> http://git.busybox.net/busybox/commit/shell/ash.c?id=4ba6c5d3ba3d2c7922aff6b5c2e73b8325f1cf17
> 
> but this commit results in crash running some shell scripts, so it was reverted.
> 
> 
> I am trying to resolve this defect,any commnent would be appreciated!

There is no easy fix. The patch you sent is incorrect. The problem is
that the "stack model" used for allocation in ash is semantically
wrong, and needs to be replaced with a dependency-tree model or
something else that can handle freeing one object without freeing all
subsequently-allocated objects.

As a workaround, it might be possible to code a hack to reuse the
existing copy of the string on the allocation stack rather than
allocating a new copy whenever an existing copy already exists. This
would not solve the general case (e.g. when the redirection uses a
different file on each iteration) but it would solve the case above, I
think. It might be worth pursuing this approach if nobody is available
to work on the proper fix in the near future.

Rich
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic