[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bacula-devel] libdbi backend to catalog database


On Wednesday 12 March 2008 12:15:21 João Henrique Freitas wrote:
> Hello,
>
> I found some memory leaks in dbic.c. In regression tests, bacula
> always report buffers not release allocates in dbi.c after run tests.
>
> Comparing to postgresql.c I have some doubts.
>
> Every call of PQgetvalue is return to row[j] (like
> my_postgresql_fetch_row):
>
>   378          for (j = 0; j < mdb->num_fields; j++) {
>   379          mdb->row[j] = PQgetvalue(mdb->result, mdb->row_number, j);
>   380          Dmsg2(500, "my_postgresql_fetch_row field '%d' has
> value '%s'\n", j,      mdb->row[j]);
>   381       }
>
> When  my_postgresql_free_result() are call,  PQclean() release every
> data in row[j]:
>
>   532    if (mdb->result) {
>   533       PQclear(mdb->result);
>   534       mdb->result = NULL;
>   535    }
>
> Suppose, If PQclear not release nothing, how I can free mdb->row?
> (mdb->row is a array of pointers)
>
> In the case, libdbi don't free like PQclear() and I do a loop and free
> every position of mdb->row[j] and mdb->row too. Like this:
>
> if (mdb->row) {
>    # if mdb->num_fields are 18, release 18 pointers...
>    for( j = 0; j < mdb->num_fields; j++) {
>         free(mdb->row[j]);
>    }
>    free(mdb->row)
>    mdb->row = NULL;
> }
>
> This is the right way or has another way to free mdb->row?

Your suggestion sounds reasonable if you explicitly malloced the buffers that 
are stored in mdb->row[j]. It is in fact probably exactly what the PQclear() 
code of PostgreSQL does. 

If you did not explicitly malloc them in your code, then they probably need to 
be free'ed in a different way. If you point me to the code that does the 
malloc, I can respond better ...

Best regards,

Kern

>
>
>
> Thanks
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Bacula-devel mailing list
> Bacula-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/bacula-devel



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bacula-devel mailing list
Bacula-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/bacula-devel


This mailing list archive is a service of Copilotco.