[OpenSER-Devel] RFC: memory management in database modules
Daniel-Constantin Mierla
daniel at voice-system.ro
Tue Feb 5 15:54:37 UTC 2008
Hello,
On 02/05/08 16:17, Henning Westerholt wrote:
> Hi,
>
> i've a question about the 'correct' way to do the memory management for
> results in the database modules.
>
> At the moment there existing two different styles:
>
> mysql, unixodbc don't allocate new memory and just assign the string pointer
> of the result set to the internal OpenSER representation. The modules that
> needs to use this results needs to copy them, because there are not available
> after a call to the DB specific result free function.
>
> postgres, db_berkeley allocate new memory and copy all string values from the
> database to the internal representation. Modules that uses this driver don't
> need to copy there values, even after the freeing of the result set.
>
quite strange, if the copy is not freed with free_result(), when it
happens? At first thought, seems exposed to memory leak.
db_berkely seems constructed on dbtext structure. In dbtext, the result
is duplicated in private memory, as the tables are stored in shared
memory, and making direct references will be exposed to race.
I think that the driver modules should not duplicate the result unless
there is some race in reading/writing values in the result. Each module
that uses the driver decides whether it needs values after free_result()
and does a copy -- this is how should be now, at least did so.
Cheers,
Daniel
> As mysql is the most used database, (i assume) that every module copy the
> values from the result set after the query execution. This is unnecessary for
> the postgres DB, and further prevents me from using only one memory
> management function for the internal representation of the DB structures.
>
> As we have many more modules than database connectors in the code, i think it
> would make more sense to change the postgres and db_berkeley module to match
> the behaviour of the mysql module.
>
> Any comments?
>
> Henning
>
> _______________________________________________
> Devel mailing list
> Devel at lists.openser.org
> http://lists.openser.org/cgi-bin/mailman/listinfo/devel
>
>
More information about the Devel
mailing list