[sr-dev] git:master: db_mysql: fix segfault when recursive queries are made

Daniel-Constantin Mierla miconda at gmail.com
Mon Apr 29 15:31:10 CEST 2013


Hello,

On 4/29/13 3:01 PM, Richard Fuchs wrote:
> Hi,
>
> On 04/29/13 07:11, Daniel-Constantin Mierla wrote:
>> Hello,
>>
>> On 4/10/13 3:36 PM, Richard Fuchs wrote:
>>> -int db_mysql_free_result(db1_con_t* _h, db1_res_t* _r);
>>> +int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r);
>> the change to the prototype of the above function is now throwing
>> compilation warning:
>>
>> km_db_mysql.c: In function ‘db_mysql_bind_api’:
>> km_db_mysql.c:109: warning: assignment from incompatible pointer type
>>
>> Do you need the const specifier? If yes, the DB API and probably the
>> other database drivers need to be updated.
> The const is needed because db_mysql_free_result is called from other
> functions which have the db1_con_t object declared as const. Removing
> the const from the prototype would trigger warnings elsewhere.
>
> The idea is that the driver-specific result set should really be stored
> in the db1_res_t object, and not in db1_con_t as the other drivers do it
> now (which was causing the segfault). Therefore, ->free_result really
> has no reason to modify the db1_con_t object, which warrants the const
> modifier. Preferably the other drivers should be updated to follow the
> same reasoning, after which the const can be put into db_func_t, but I
> don't have enough experience with them to do it myself.
>
> Alternatively, the const could probably be removed from this and a few
> other function prototypes, or maybe a wrapper function could be used.

your patch is incomplete/wrong in a way or another -- you introduced a 
warning in the piece of code you changed. It will be still wrong if the 
warning will be in another place, so choosing one instead of the other 
is not a solution.

You can probably cast to const whenever it is required so by a calling 
function, rather than changing the prototype and leaving it with warning 
like this, if you don't know how to/can't update the other drivers for 
various reasons.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Training, San Francisco, USA - June 24016, 2013
   * http://asipto.com/u/katu *




More information about the sr-dev mailing list