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

Posted on 2004-08-16
Last Modified: 2012-05-05

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/

Here is the section of code that  closes the file:

      if (m_fptr)

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

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



Question by:rfr1tz
LVL 40

Accepted Solution

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.

Expert Comment

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?
LVL 23

Assisted Solution

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.


Author Comment

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,


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