Solved

What can cause Segmentation fault inside fclose@@GLIBC_2.1 () from /lib/tls/libc.so.6?

Posted on 2004-08-16
4
1,005 Views
Last Modified: 2012-05-05
Hi

I'm running a program in Linux. This program reads a file, execute some commands based on the content of the file. After completing all the commands, the program closes the file. The program crahses (Segmentation Fault) when it closes the file. I used gdb stack trace (bt) to track where the Segmentation fault occurred and found that it occurs inside the function fclose@@GLIBC_2.1 () from /lib/tls/libc.so.6.

Here is the section of code that  closes the file:

//-----------
      if (m_fptr)
      {
            fclose(m_fptr);
      }
//-----------

Here is the logs:
Program received signal SIGSEGV, Segmentation fault.
0xb7386333 in fclose@@GLIBC_2.1 () from /lib/tls/libc.so.6

If you've any idea why the program crashes inside fclose@@GLIBC_2.1 () from /lib/tls/libc.so.6, please help.
Any suggestion would be appreciated.

Thanks,

Rfr1tz




0
Comment
Question by:rfr1tz
4 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 150 total points
ID: 11814196
My guess would be that m_fptr has been trashed after the last prior use and befor the if() statement.
0
 
LVL 7

Expert Comment

by:aib_42
ID: 11815714
We cannot deduce the error from these 4 lines. It is very likely that your program has caused undefined behaviour somewhere prior. Can you post the code?
0
 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 100 total points
ID: 11815729
There are 4 common programming errors that would result in this:

1) m_fptr was not initialized to NULL, and some code path gets
to the call to fclose() without ever giving m_fptr a value.

2) the file has already been closed, but m_fptr was not reset to NULL.

3) you managed to overwrite the m_fptr variable, trashing the FILE pointer.

4) you managed to trash the FILE structure pointed to by m_fptr.






0
 
LVL 3

Author Comment

by:rfr1tz
ID: 11817549
Hi all,

Thanks  so much for your help.
Exactly as jlevie and brettmjohnson pointed out: the file has been closed/trahsed but m_fptr was not set to NULL.
I got it right now.

Thanks again,

Rfr1tz
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i create a game board using shell script 2 76
what does getent do 3 50
generating rpm using noarch parameter 1 40
CRON expression that fires every other Tuesday 3 105
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question