Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-16
4
Medium Priority
?
1,173 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 600 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 400 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

Independent Software Vendors: 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 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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview
Suggested Courses

885 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