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

List:       busybox
Subject:    Re: bug-report: ash: fix a memory leak
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2015-01-07 17:37:31
Message-ID: CAK1hOcOqzgvjAPu7KvmvQ=SHXCgy1VLE-uNB1ZriMX3heLrcOA () mail ! gmail ! com
[Download RAW message or body]

On Wed, Dec 24, 2014 at 6:53 AM, Rich Felker <dalias@libc.org> wrote:
> 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.

You can try using hush instead of ash. It has no such problem,
because it does not try to be clever, and just uses malloc.
_______________________________________________
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