Subject | Re: [ib-support] firebird api: who deallocs memory? |
---|---|
Author | John Bellardo |
Post date | 2002-02-21T16:20:32Z |
Hi,
On Thursday, February 21, 2002, at 07:57 AM, C R Zamana wrote:
>
> Hi fellows,
>
> Below is an excerpt of my code. This function handles the
> connection.
>
> The question is: who must free the dpb variable?
>
> I'm asking because when I try to free it my program
> crashes, even if this free is called from the disconnection
> function, after the disconnection.
>
> I'm worry about this because my daemon is eating memory,
> even if all that is done by the client is just connect and disconnect.
> As long as I could check this is the only piece of memory that I'm
> not freeing explicitly.
>
I think your problem is the use of isc_expand_dpb. That function does
not do what you expect, and is poorly documented AFAIK. I suggest
stuffing the user name and password into the dpb yourself, and seeing if
that makes a difference. In terms of freeing the dpb, I'm pretty sure
it is safe to do so as soon as isc_attach_database returns.
-John
> #include "rdd_api.h"
>
> extern char *dpb;
>
> ISC_LONG api_connect( char *db, char *user, char *pass, isc_db_handle
> *dbhandle ) {
>
> short dpb_length;
> ISC_STATUS status_vector[20];
>
> dpb = (char *)malloc(USERNAME_SIZE+PASSWORD_SIZE+2);
> if ( dpb == NULL ) {
> return(-1);
> }
>
> dpb_length = 0;
>
> isc_expand_dpb( &dpb, &dpb_length, isc_dpb_user_name, user,
> isc_dpb_password, pass, NULL );
>
> isc_attach_database( status_vector, 0, db, dbhandle, dpb_length, dpb
> );
>
> if ( status_vector[0] == 1 && status_vector[1] ) {
> isc_print_status(status_vector);
> }
>
> return( isc_sqlcode(status_vector) );
> }