人気ブログランキング | 話題のタグを見る

[c][MYSQL] c から MYSQL で SIGSEGV

C + mysql のプログラムを作っています。
とにかく突貫で作らなくてはならず、
オシャレなコードにこだわっている暇はありません。
(そんなわけで、ここ数日、帰宅が午前1時近いです…)
1年ほど C 言語を書いていなかった私としては、
バグが発生するようなことは、なるべく避けたいわけで、
それで、今のところ、alloc を使わないで作っています(爆笑)

まぁ、幸い、マルチスレッドとか、
複数プロセス走らせるとか、そういうのじゃないので、
メモリはギリギリまで使っても大丈夫な雰囲気。

ところが、何故か SIGSEGV を発生して core を吐くわけです。
しかも、mysql の関数の中です。
1回目、2回目は大丈夫で、3回目で落ちる。
mysql_use_result の後には、必ず mysql_free_result をしているから、
そういう方面の問題でもなさそう。
一応、情報共有のために、gdb の結果を以下に。

Buffers Files Tools Edit Search Mule Help
Current directory is /home/***/***/
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) r

Program received signal SIGSEGV, Segmentation fault.
0x400c3fd4 in __libc_free (mem=0x401725e0) at malloc.c:3152
3152 malloc.c: No such file or directory.
in malloc.c
(gdb) bt
#0 0x400c3fd4 in __libc_free (mem=0x401725e0) at malloc.c:3152
#1 0x40023c33 in my_no_flags_free () from /usr/lib/libmysqlclient.so.12
#2 0x40034c16 in vio_delete () from /usr/lib/libmysqlclient.so.12
#3 0x4001ed69 in end_server () from /usr/lib/libmysqlclient.so.12
#4 0x4001e8dd in simple_command () from /usr/lib/libmysqlclient.so.12
#5 0x400215ac in mysql_send_query () from /usr/lib/libmysqlclient.so.12
#6 0x400217a8 in mysql_real_query () from /usr/lib/libmysqlclient.so.12
#7 0x40021348 in mysql_query () from /usr/lib/libmysqlclient.so.12
#8 0x0804aab0 in *** (mysql=0x8384e88,
***=0xbffff558 "***", ***=0xbffff595 "***",
***=0xbffd0fd8 "**") at ***.c:668
#9 0x08049dfe in *** (***=0xbffff6e8, ***=5,
mysql=0x8384e88, ***=0xbfff704c "0") at ***.c:286
#10 0x08049b30 in *** (***=0xbffff6e8,
***=0xbfff9094 "3", ***=3, conf=0xbffff0c0, ***=0xbfffd0c0 "0",
***=0xbfffb0c0 "", ***=0xbfff90c0 "") at ***.c:145
#11 0x0804b682 in main (argc=1, argv=0xbffff764) at ***.c:1306
#12 0x4006a13f in __libc_start_main (main=0x804b29c <main>, argc=1,
ubp_av=0xbffff764, init=0x804924c <_init>, fini=0x80ae240 <_fini>,
rtld_fini=0x4000c770 <_dl_fini>, stack_end=0xbffff75c)
at ../sysdeps/generic/libc-start.c:129


mysql の中の free ???
何で mysql_query で落ちるん?
少なくともワタシは free なんて使ってないから、、
そんなトコでダメ言われても、なんでか全然わからん。

C ってあまり書いた事がないから、
こういう時、気持ちをわかってあげられないんだよねぇ。
歯がゆい。

因みに、環境は以下。
OS   Vine Linux 2.4.22-0vl2.10
mysql  Ver 12.22 Distrib 4.0.23
gcc  Ver 2.95.3 20010315

【その後】
#ifdef DEBUG で、fprintf を沢山使っていたのですが、
それをいくつか削除したら、
エラーが出なくなりました。
なんで???

理由はわからないけれど、治ったから良いや<ホント?
2日も悩んで損したー(怒

追記:
考えてみたら、スタックオーバフローを起こしていたのかもしれない。
今となっては検証の仕様もないんだけどねー。
ローカル変数に片っ端から static とかつけて、
それでも落ちないか、試してみれば良かったのかも。
by xiaoxia | 2005-04-15 20:58 | プログラム言語
<< 私はメーテル 切手になる女…… Linux のワインリスト >>