473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

programs holds on malloc

Hi,

I don't know if this is the right newsgroup to ask this so if i'm wrong
please redirect me.

Here's my problem, i sometimes get that my program ( a server ) just stops
reacting, if
i use gdb and do a backtrace i get this:

#0 0x402331d1 in _int_malloc () from /lib/libc.so.6
#1 0x402320cf in malloc () from /lib/libc.so.6
#2 0x0804ab9d in mysql_getUserid ()
#3 0x0804a7b9 in protocol_checkSocket (socket=6, username=0x8052498
"blaat")
at protocol.c:344
#4 0x0804a281 in protocol_process (buf=0x804d2e0 "add", socket=6)
at protocol.c:224
#5 0x08049343 in network_process (buf=0x804d2e0 "add", socket=6)
at network.c:133
#6 0x080492ef in network_loop () at network.c:119
#7 0x08048f22 in main (argc=5, argv=0xbffffb44) at main.c:61
#8 0x401d490b in __libc_start_main () from /lib/libc.so.6

Looks to me like it stops working in malloc? I've included the
mysql_getUserid function soyou can tell me if somethings is wrong.

int mysql_getUserid(char * username)
{
MYSQL_RES * res_set;
MYSQL_ROW row;
char * sql;

if((sql=malloc(256*sizeof(char))) == NULL)
{
printf("Malloc failed at mysql_getUserid!\n");
return -1;
}
sprintf(sql, "SELECT userid FROM userlist WHERE username='%s'", username);
if(mysql_query (conn, sql) != 0)
{
free(sql);
return -1;
}
res_set = mysql_store_result(conn);
if(!mysql_num_rows(res_set) > 0) return -1;
row=mysql_fetch_row(res_set);
mysql_free_result(res_set);
free(sql);
return atoi(row[0]);
}

I don't know why it happens sometimes, most of the time the function just
works fine...
If anyone got a solution, please tell me...
Thanks in advance,

Robert Mens


Nov 14 '05 #1
1 1335


Robert wrote:
Hi,

I don't know if this is the right newsgroup to ask this so if i'm wrong
please redirect me.

Here's my problem, i sometimes get that my program ( a server ) just stops
reacting, if <snip> if((sql=malloc(256*sizeof(char))) == NULL)
{
printf("Malloc failed at mysql_getUserid!\n");
return -1;
} <snip> if(!mysql_num_rows(res_set) > 0) return -1;


There may be other problems too, but this looks like a memory leak - you
don't free sql before returning.

Ed.

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: iceColdFire | last post by:
Hi, I am writing some hybrid application s using C/C++ modules together....Here I have created and used a lot of malloc(...) and new(...) operators. I am interested in checking on the...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
27
by: HKSHK | last post by:
Hello, I have this problem: I wrote some DLLs with VB.Net 2003 which I use with my programs. But I want to avoid that I have to go down to "DLL hell" and to copy all used dlls into each program...
20
by: Guy Fawkes | last post by:
Hi, I was wondering if Python programs always need to include the source code with the program itself. I'm asking this because I don't want my program to be open-source and so far all the Python...
24
by: c language | last post by:
Hello all, I am using 'Valgrind' to fix the memory leaks of my programs. I am looking for other programs to see how they are detecting the problems. Does any of you have experience in working...
2
by: rsteph | last post by:
I took a number of classes back in college with Java, VB, and VB.NET, and a few in C++. I was looking through some of my books the other day and decided to brush up on my C++ programming, as I'd like...
1
by: Nithya Kalyani | last post by:
Hi Expert, I m a student, can any one help me in finding the answer of below one. The C programs given below contain errors, rectify them as needed. a) void main() { char linebuf; char...
8
by: aarklon | last post by:
Hi all, see:- http://linuxgazette.net/issue51/pramode.html
5
by: yassu | last post by:
some new intresting c programs visit http://cpp4students.blogspot.com/
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.