[sr-dev] need help understanding pv_value_destroy

Daniel-Constantin Mierla miconda at gmail.com
Mon Jan 5 13:39:15 CET 2015


Hi Luis,

you should not care about the script interpreter inside your C code. It
does freeing of pv value, if needed (the interpreter executes
pv_value_destroy() when needed).

The flags PV_VAL_PKG or PV_VAL_SHM must be set only (when needed) by a
pv or transformation implementation. It is not necessary to use them if
you call the ->setf() function from a pv, because that setf function
will copy the value to its own structure.

Cheers,
Daniel

On 05/01/15 13:25, Luis Azedo wrote:
> Hi Daniel,
>
> if i understand it correctly, it is safe to call  pv_value_destroy
> after assigning the $var(..) in module code.
>
> i still have doubt on when and how to free the result of a transform
> returned value.
>
> in script
> if( $(myPvar{my.mytransform,transformParameter}) =="test value") {
>  $var(x) = $(myPvar{my.mytransform,transformParameter});
> }
>
> in module i assign the returned value of transform with dst_val->flags
> = PV_VAL_STR | PV_VAL_PKG;
> since this line "if( $(myPvar{my.mytransform,transformParameter})
> =="test value") {" is allocating memory, will it be freed by script
> with pv_value_destroy  ?
> this line "$var(x) = $(myPvar{my.mytransform,transformParameter});"
> assigns the returned value to a variable, will the script free the
> right side of the expression ? will it use pv_value_destroy  ?
>
>
> Thanks
>
>
> ------------------------------------------------------------------------
> *From:* sr-dev [sr-dev-bounces at lists.sip-router.org] on behalf of
> Daniel-Constantin Mierla [miconda at gmail.com]
> *Sent:* Monday, January 05, 2015 3:59 AM
> *To:* Kamailio (SER) - Development Mailing List
> *Subject:* Re: [sr-dev] need help understanding pv_value_destroy
>
> Hello,
>
> if you assign to a $var(...), it makes a deep copy in pkg memory. It
> is up to you to handle further the content of dst_val and free it
> properly.
>
> If you set the PV_VAL_PKG (value must be in a pkg_malloc() pointer) or
> PV_VAL_SHM (value must be in a shm_malloc() pointer) for dst_val, then
> you can call pv_value_destroy() to get it freed. But it is not
> necessary, if you free it in the code yourself.
>
> Cheers,
> Daniel
>
> On 04/01/15 12:36, Luis Azedo wrote:
>> Hi Daniel,
>>
>> can you help on this ?
>>
>> ------------------------------------------------------------------------
>> *From:* sr-dev [sr-dev-bounces at lists.sip-router.org] on behalf of
>> Luis Azedo [luis at 2600hz.com]
>> *Sent:* Wednesday, December 31, 2014 4:19 AM
>> *To:* sr-dev at lists.sip-router.org
>> *Subject:* [sr-dev] need help understanding pv_value_destroy
>>
>> Hi,
>>
>> in some function that return a value with PV_VAL_PKG or PV_VAL_SHM,
>> the allocated memory is supposed to be freed by core ? 
>>
>> script example
>>
>> my_function("some param","$var(result)");
>>
>> in code => 
>> dst_val->flags = PV_VAL_STR | PV_VAL_PKG;
>> dst_pv->setf(msg, &dst_pv->pvp, (int)EQ_T, &dst_val);
>>
>> when $var(result) is freed, will it free the allocated string ?
>>
>>
>> if( $(myPvar{my.mytransform,transformParameter}) == $null) {
>>  $var(x) = $(myPvar{my.mytransform,transformParameter});
>> }
>>
>> in code => 
>> dst_val->flags = PV_VAL_STR | PV_VAL_PKG;
>>
>> will the memory allocated be freed  in the comparison line ?
>> will the memory allocated be freed  when $var(x) is freed ?
>>
>> thank you
>>
>>
>>
>> _______________________________________________
>> sr-dev mailing list
>> sr-dev at lists.sip-router.org
>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
> -- 
> Daniel-Constantin Mierla
> http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda

-- 
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20150105/07d7900a/attachment.html>


More information about the sr-dev mailing list