Re: [gnome-db] GDA 0.2.96 Memory leaks



On Mon, 2002-05-06 at 23:37, Stéphane Raimbault wrote:
> Hi,
> 
> To learn GDA's API, I read gda-test.c but I found many memory leaks :
> 
> --- gda-test.c  Mon May  6 23:13:11 2002
> +++ gda-test-fix.c      Mon May  6 23:13:11 2002
> @@ -148,9 +148,12 @@
>         for (gda_recordset_move_first(rs); !gda_recordset_eof(rs);
>              gda_recordset_move_next(rs)) {
>                 for (i = 0; i < gda_recordset_rowsize(rs); i++) {
> +                       char *s_value = NULL;
>                         field = gda_recordset_field_idx(rs, i);
> -                       g_print("%s=%s\t", gda_field_get_name(field),
> -                               gda_stringify_value(NULL, 0, field));
> +                       s_value = gda_stringify_value(NULL, 0, field);
> +                       g_print("%s=%s\t", gda_field_get_name(field),
> s_value);
> +                       g_free(s_value);
> +                       gda_field_free(field);
>                 }
>                 g_print("\n");
>         }
> @@ -193,5 +196,6 @@
>         list_tables(cnc);
>         g_print("\nclosing connection...\n", provider);
>         gda_connection_free(cnc);
> +       g_free(provider);
>         return (0);
>  }
> 
committed

> -------------------------------------------------------------------------
> 
> So now, I think this file isn't a good example to learn GDA.
> 
> I used memprof to find memory leaks in my code and it finds many
> errors on gda_connection_execute :
> - maybe I don't use correctly GDA
> - maybe memprof it's not the good tool
> 
> Are these following examples right ?
> 
> Connection :
> 
> gda_init("test-db", NULL, argc, argv);
>         
> gda_cnc = gda_connection_new(gda_corba_get_orb());
> gda_connection_set_provider(gda_cnc,  
> "OAFIID:GNOME_GDA_Provider_Postgres_Connection");
>         
> if (gda_connection_open(gda_cnc, "DATABASE=sps", "piid_user", NULL))
> 	die(gda_cnc);
> 
> gda_connection_free(gda_cnc);
> 
yes, this one is correct

> Requests:
> 
> GdaRecordset *gda_rs;
> gulong nb_cols = 0;
> gulong gda_flags = 0;
>         
> gda_rs = gda_connection_execute(gda_cnc,
>                                 "SELECT * FROM table",
>                                 &gda_nb_lines, gda_flags);
> gda_recordset_free(gda_rs);
> 
yes

> Fields:
> 
> GdaField *field;
> field = gda_recordset_field_idx(rs, i);	
> gda_field_free(field);
> 
yes

> Bye
> 
> Stephane
> 
> PS: GDA 0.8.X seems cleaner.
> 
yes, much more cleaner. Please use it instead, if that's possible at
all.

cheers



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