Solved

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

Posted on 2004-08-16
4
1,068 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
[X]
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
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

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 (https://www.adremsoft.com/). 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