LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2007, 12:18 AM   #1
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Rep: Reputation: 15
malloc hangs


Hello,

can any one help me to solve this _int_malloc() hangs issue. please see the gdb back-trace it shows _int_malloc() is hanging, i waited so much of time still _int_malloc taking time, can anybody help me to solve this issue?

(gdb) bt
#0 0x001babcc in _int_malloc () from /lib/tls/libc.so.6
#1 0x001b9ecd in malloc () from /lib/tls/libc.so.6
#2 0x001aa4f3 in popen@@GLIBC_2.1 () from /lib/tls/libc.so.6
#3 0x080599d2 in Function1() at c1.cxx:281
#4 0x08061c1d in main (argc=13, argv=0xfeffd874) at main.cxx:172
(gdb) quit

Thanks & Regards
Dayalan
 
Old 05-26-2007, 07:07 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Are you absolutely positive that you don't have an infinite loop in there somewhere?

If malloc cannot call brk() successfully (if it needs to) it immediately returns NULL. If you check the return code of malloc you will find out if malloc is the problem.

It is slightly possible, if you are using an alternate malloc package, that it has a bug in it.

What distibution are you on?
 
Old 05-27-2007, 08:54 AM   #3
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jim mcnamara
Are you absolutely positive that you don't have an infinite loop in there somewhere?

If malloc cannot call brk() successfully (if it needs to) it immediately returns NULL. If you check the return code of malloc you will find out if malloc is the problem.

It is slightly possible, if you are using an alternate malloc package, that it has a bug in it.

What distibution are you on?
Hi Jim,

please see the back-trace, after the popen call, it internally calls malloc function and malloc calls _int_malloc() when i was debugging the code, it works fine before i reach popen(), exactly on popen() i did next in gdb, that is it and it was waiting so much of time then i pressed Ctrl-C, then i did back-trace.

please help me to understand and solve this issue.

Thanks & Regards
Dayalan
 
Old 05-27-2007, 12:10 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
What glibc are you using (and can we have some sample code)?
 
Old 05-27-2007, 11:02 PM   #5
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by osor
What glibc are you using (and can we have some sample code)?
My glibc Version:

glibc-2.3.2-95.33

Sample Code: [ this sample code works, but in my project popen hangs/stuck ]

#include<stdio.h>

int main()
{
FILE *fp;
char Name[256];
int Priority;

fp=popen("List.pl","r");

if(fp == NULL)
{
printf("Null Pointer\n");
}
fscanf( fp, "%d %s", &Priority, Name);
printf("Priority: %d\nName: %s\n",Priority,Name);
close(fp);
}

Please let me know your inputs.

Thanks & Regards
Dayalan
 
Old 05-28-2007, 08:28 PM   #6
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
If popen works in the sample code but not in your project, it's conceivable that in the latter something else corrupts the heap before you get to popen. I've had good experience using valgrind for finding many kinds of not-so-clean memory use. So you could try running your project under valgrind.
 
Old 05-28-2007, 09:13 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by dayalan_cse
Sample Code: [ this sample code works, but in my project popen hangs/stuck ]
I don’t see the point of providing us with working code (or am I misreading?)…

How is this supposed to help us solve the bug? Give us as short a code sample as possible that does experience the problem.
 
Old 06-01-2007, 02:27 AM   #8
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by osor
I don’t see the point of providing us with working code (or am I misreading?)…

How is this supposed to help us solve the bug? Give us as short a code sample as possible that does experience the problem.
Hello All,

thank you for every body who responded to my mail. we fixed and the issue is with malloc(), we allocated less no of bytes for the variable so popen() functions waits.

thanks you once again.

Thx
Dayalan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
malloc vs calloc aaratik Programming 13 05-04-2007 06:33 PM
malloc anoosh Programming 1 03-15-2006 04:41 PM
malloc eagle683 Programming 6 05-22-2005 02:40 PM
malloc() vijeesh_ep Programming 4 08-25-2004 03:50 PM
about malloc eshwar_ind Programming 11 02-18-2004 03:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration