LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-19-2005, 07:43 AM   #1
pippet
Member
 
Registered: May 2004
Posts: 67

Rep: Reputation: 15
segmentation fault


Hi,
I am using the gcc-3.3.3 which comes along with the FC2 release. When i tried to run a program i got a segmentation error in the following code

for(int i=0; i < temp.count; i++) {
temp.str[i] = new wchar_t[moods[i].length()]; //this will give u error for i=2
wcscpy(temp.str[i], moods[i].c_str());
}
Here moods[i].lengh() is 768 for i=2 and at that point it crashes.


bt is
0x0042cd58 in _int_malloc () from /lib/tls/libc.so.6
#1 0x0042c09d in malloc () from /lib/tls/libc.so.6
#2 0x001a43ae in operator new () from /usr/lib/libstdc++.so.5
#3 0x001a44df in operator new[] () from /usr/lib/libstdc++.so.5

What could be the problem?

pippet
 
Old 01-19-2005, 08:28 AM   #2
Quis
Member
 
Registered: May 2001
Location: Germany, Süd-Baden
Distribution: Gentoo
Posts: 139

Rep: Reputation: 15
is moods[i] at i=2 initialized?
Or, what is the value of moods[2].lenth?
Does gcc put out a warning?
Did you "malloc"ed temp.str?

Last edited by Quis; 01-19-2005 at 08:30 AM.
 
Old 01-19-2005, 10:19 PM   #3
pippet
Member
 
Registered: May 2004
Posts: 67

Original Poster
Rep: Reputation: 15
It is initailized properly. Today i again run the program(after a restart). Fro the second time it completed the exception without any error. Is there any way to trace the memory leak in the program?
 
Old 01-20-2005, 02:20 AM   #4
Quis
Member
 
Registered: May 2001
Location: Germany, Süd-Baden
Distribution: Gentoo
Posts: 139

Rep: Reputation: 15
You can try "valgrind" it's a useful tool to check memory assignment.

You said "It is initailized properly". Did you checked the *temp.str too?
 
Old 01-24-2005, 01:02 AM   #5
pippet
Member
 
Registered: May 2004
Posts: 67

Original Poster
Rep: Reputation: 15
I got it, the function moods[i].length() returns random values like 763,765 etc.
But i think malloc returns a rational value if it receives such values.
 
  


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
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 04:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 11:13 AM
Segmentation fault tejas15_10 Programming 9 06-20-2005 09:12 AM
Segmentation fault santhosh_o Programming 3 10-26-2004 05:45 AM

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

All times are GMT -5. The time now is 08:26 AM.

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