Bug #29819 | MySQL-functions are causing "Bus error". | ||
---|---|---|---|
Submitted: | 16 Jul 2007 12:32 | Modified: | 16 Jul 2007 12:52 |
Reporter: | Vincent David | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S2 (Serious) |
Version: | 5.0.45 | OS: | MacOS (Tiger (10.4.10)) |
Assigned to: | Sveta Smirnova | CPU Architecture: | Any |
Tags: | bus error, mysql_init, mysql_real_connect., segfault, segmentation fault |
[16 Jul 2007 12:32]
Vincent David
[16 Jul 2007 12:33]
Vincent David
example source
Attachment: MySQLTest_broken.c (text/plain), 760 bytes.
[16 Jul 2007 12:52]
Hartmut Holzgraefe
We're sorry, but the bug system is not the appropriate forum for asking help on using MySQL products. Your problem is not the result of a bug. Support on using our products is available both free in our forums at http://forums.mysql.com/ and for a reasonable fee direct from our skilled support engineers at http://www.mysql.com/support/ The problem is that you are using *unallocated* memory in your first example while using (implicitly) allocated memory in the 2nd where the MYSQL structure is implicitly allocated on the functions local variable stack. Passing on an unallocated/uninitialized pointer may fail right away or may seem to work at first depending on compiler options etc... but is a wrong thing nonetheless. Adding a mysql = (MYSQL *)malloc(sizeof(MYSQL)); would help to prevent the problem you are facing just the same way that making it a local variable does. Thank you for your interest in MySQL.