At 19:32 +0100 12/13/04, Alina BiŸkowska wrote:
Description:
When I try to call mysql_init() several times in my program it finishes with segmentation fault.
This happens in different places of my program but always in mysql_init().
This is the gdb output:


#0 0x007ba6ae in malloc_consolidate () from /lib/tls/libc.so.6
#1 0x007b9e6a in _int_malloc () from /lib/tls/libc.so.6
#2 0x007b925d in malloc () from /lib/tls/libc.so.6
#3 0x001716ae in my_malloc () from /usr/local/lib/mysql/libmysqlclient.so.12
#4 0x0016c648 in mysql_init () from /usr/local/lib/mysql/libmysqlclient.so.12
#5 0x0804dee2 in myconnect () at databaseFunctions.c:14
#6 0x0804dfc0 in give_geneValue_with_key (table=0x8051fe8 \"selfRoot_shell\", id=9463)
at databaseFunctions.c:37
#7 0x08049a27 in selfProfiler () at library.c:232
#8 0x0804952c in negativeSelection () at library.c:176
#9 0x0804a92d in negativeSelectionSentinel () at library.c:420
#10 0x0804edad in communicator (arg=0x755d00) at communicator.c:60
#11 0x08048cdf in main () at primary.c:169



Here are the functions I use. The first function is only to make a connection to database:

MYSQL* myconnect()
{
   MYSQL *my_connection=malloc(sizeof(MYSQL *));
my_connection=mysql_init (NULL);

I don't think this solves your problem, but I'm curious:

Why do you allocate memory and assign it to my_connection, and then
immediately throw that memory away by assigning my_connection the value
of mysql_init()?  That's a memory leak right there.



if(mysql_real_connect (my_connection, \"130.225.16.5\", \"ala\", \"alaSdb\", \"ala\", 0, NULL, 0))
{
return my_connection;
}
else
{
fprintf (stderr, \"Connection failed !!!\\n\");
if (mysql_errno (my_connection))
{
fprintf (stderr, \"Connection error %d: %s\\n\", mysql_errno (my_connection), mysql_error (my_connection));
return NULL;
}
}
return NULL;
}


This function and a couple of others similar are to withdraw some data from database. All of them use myconnection() function;

char* give_geneValue_with_key(char *table,int id)
{

  MYSQL* my_connection=myconnect();
  MYSQL_RES *result=malloc(sizeof(MYSQL_RES*));
  MYSQL_ROW row;
  char temp[10000];
     sprintf(temp,\"SELECT geneValue FROM  %s where id=\'%d\'\",table,id);

     if(mysql_real_query (my_connection,temp,strlen(temp))) return \"0\";
     if(!(result=mysql_store_result(my_connection))) return \"0\";
     row=mysql_fetch_row(result);
     mysql_free_result(result);
     mysql_close(my_connection);
     return row[0];
}

If you have any ideas what can be a problem, please let me know.
Alina Binkowska


--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

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



Reply via email to