Hallo,

> 
> in a very small representation the program is this
> 
> *** dbmail and dbmail2 open 2 different connections, one accesses
> DBM_ADDRESSES table and the other accesses DBM_NAMES table. The first one
> retrieves addresses from the table DBM_ADDRESSES, the second one a relationed
> names to the addresses from DBM_NAMES. Not all addresses have name set, so
> for questions of space I separated into tables, just 10% of addresses have a
> name and it would be waste of space having that column in the same table
> (90%+ of over 50,000 rows), so I created a new table for the names and linked
> them to a corresponding address via an 'id'

Are your two tables in the same database ?
If yes only one connection if enough, and you could use a join query
to do it, thus having a speed improvement of several magnitudes.

 
> 1. connect dbmail and dbmail2 to server
> 2. dbmail.query:   SELECT id,address from DBM_ADDRESSES WHERE ...
>     sp_id = atoll(record[0]); // stores the id in 'sp_id'
> 3. while ( dbmail retrieves rows from query at step 2 ) {
>    dbmail2.query:
>    3.1 SELECT name FROM DBM_NAMES WHERE id=sp_id(from step 2)
>    3.2 if ( name exists for id=sp_id )
>            do something with DBM_ADDRESSES.address,DBM_NAMES.name
>         else
>            do something with DBM_ADDRESSES.address
>    3.3 free results from dbmail2.query (inside while)
>    }
> 4. free results from dbmail.query (1st query before while) ***CRASH***
> 5. disconnect dbmail and dbmail2 connections
> 
> The crash is in step #4 after  all data is retrieved successfully, but why?

Have you checked that you free the correct result ? set it to NULL
after used, and add a test for nullity, it may help.
What version of the API are you using ? which OS ?
Have you check bugs.mysql.com ?

> 1. query: SELECT ...
> 2. while ( fetch rows ) { use the results }
> 3. mysql_free_result()
> 
> it crashes too, this model is very (really very simple) and does not leave
> space for errors in code and still fails on the free function...
> 

pseudo-code won't crash as far as I can tell :-)

> I've asked on a linux list and somebody told me just to avoid using
> mysql_free_result() if the program works that way ('cos the results maybe are
> being already free by the library), but I don't think it is a solution, I
> want to know what happens, if really the set is free automatically by the C
> API functions after reading it or not, and if so, why the documentation tells
> that it is a *must* call the free function after the whole set of rows is
> retrieved...
> 

That would leave a nice memory leak indeed...
eventually, recompile and set a break-point before calling mysql_free,
and look at all variables.

-- 
Pooly
Webzine Rock : http://www.w-fenec.org/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to