[Glass] How can I release a malloced CByteArray ....

James Foster james.foster at gemtalksystems.com
Wed Feb 26 09:16:20 PST 2014


"The POSIX function putenv() is used to set environment variable values. The putenv() function does not create a copy of the string supplied to it as an argument; rather, it inserts a pointer to the string into the environment array.” In this situation the caller typically does a malloc() without a free().

https://www.securecoding.cert.org/confluence/display/seccode/POS34-C.+Do+not+call+putenv()+with+a+pointer+to+an+automatic+variable+as+the+argument


On Feb 26, 2014, at 8:42 AM, James Foster <James.Foster at GemTalkSystems.com> wrote:

> I’ll let you take that up with the authors of the external library. In the off chance that you are faced with a situation where the authors do not accept your suggestion to rewrite their library, you can still use it.
> 
> James
> 
> On Feb 26, 2014, at 8:28 AM, itlists at schrievkrom.de wrote:
> 
>> Hmmm,
>> 
>> I thought that if I talk to an external library it is very good
>> programming practice that each component is responsible for allocating
>> and freeing their memory. This is very true, if both systems are working
>> with different memory allocation libraries.
>> 
>> That means, if I give a malloced memory to an external library the
>> external library should not free "my" memory.
>> 
>> Marten
>> 
>> 
>> Am 26.02.2014 17:12, schrieb James Foster:
>>> The short answer is “you can’t!” As indicated in the method comment, this is intended to be used to pass to C functions that take responsibility for freeing the memory. In most cases you should use CByteArray class>>#'gcMalloc:’ so that the external memory is freed automatically when the object is no longer referenced within Smalltalk.
>>> 
>> 
>> 
>> 
>> -- 
>> Marten Feldtmann
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140226/7b9d0b95/attachment.html>


More information about the Glass mailing list