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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

717 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