开发者

mysql_use_result stomping over used memory Ansi-C

i got a problem and 开发者_运维知识库its driving me nuts.

in a function called cargo_id_whitelist(MYSQL * conexion,struct info * data)

i perform a mysql Query. but every time i call the mysql api funcion mysql_use_res(conexion) it stomp over used memory, ruining data (mostly of the data structure)

example

printf("-kind-> %d \n",conf_var->next->next->id) //work its display the third node id info;
res=( MYSQL_RES *)mysql_use_result(conexion); //this break my memory
printf("puntero %p \n",res);
printf("-kind-> %d \n",conf_var->next->next->id); //segfault

conf_var is a linked list.

theres is something i need to know?


If, as in your comment, your code is as follows:

MYSQL *conn;
if (!mysql_real_connect(conn, blah, blah, blah)) {
    return 1;
}

then you're breaking the rules and all bets are off. The MySQL documentation page for mysql_real_connect() states:

The first parameter should be the address of an existing MYSQL structure. Before calling mysql_real_connect() you must call mysql_init() to initialize the MYSQL structure.

The statement MYSQL *conn; (assuming it's not static storage duration) simply creates a pointer that points to an arbitrary location and, unless you init it, using it is likely to cause you a great deal of grief.

The fix is probably simply replacing:

MYSQL *conn;

with:

MYSQL *conn = mysql_init (NULL);

That will give you a new object, properly initialised, that you can then pass to mysql_real_connect().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜