[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How far should one go preventing potential memory leaks?
- From: Marc Balmer <marc@...>
- Date: Tue, 10 May 2016 09:42:00 +0200
> Am 10.05.2016 um 09:13 schrieb Thomas Jericke <firstname.lastname@example.org>:
> On 05/10/2016 09:10 AM, Thomas Jericke wrote:
>> On 05/10/2016 08:41 AM, Marc Balmer wrote:
>>> This prevents a memory leak if lua_pushstring() raises an error, but I will end
>>> up with a number of rather small allocations that are only used for a short
>>> period of time.
>> If they buffers are really that small, I would just use the stack.
>> char s;
>> snprintf(s, sizeof(s), "bumblebee");
>> lua_pushstring(L, s);
> PS. I swear I typed this before I saw Sean's answer :-/
Well, in the real code the allocations are made for user supplied parameters, so I don't
know neither the size of the parameters not their count (which can be up to 65535), so
I really need to allocate the memory.
However, many thanks to everyone who replied.