Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-26-2003, 03:21 PM
|
#1
|
|
Member
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488
Rep:
|
seg fault on fclose ();
I tried everything! Can somebody help me with this?
Code:
bash-2.05b$ uname -a
CYGWIN_NT-5.0 <computername>1 1.3.20(0.73/3/2) 2003-02-08 12:10 i686 unknown unknown Cygwin
Code:
void load_jump_table() {
FILE * jt_file;
char * buffer = (char *) malloc(BUFSIZE * sizeof(size_t));
<SNIP>
if ((jt_file = fopen(JUMPFILE, "r")) == NULL) {
fprintf(stderr, "%s could not be opened for writing\n", JUMPFILE);
exit(1);
}
<SNIP>
jump_table = (unsigned long *) malloc((word_range[RANGE_HIGH] - word_range[RANGE_LOW]) * sizeof(size_t));
while (!(bytes_read < BUFSIZE)) {
bytes_read = fread((void *) buffer, sizeof(char), BUFSIZE, jt_file);
<SNIP>
}
if (jt_file) fclose(jt_file); /* this friggin' line */
free((void *) buffer);
}
Code:
Program received signal SIGSEGV, Segmentation fault.
0x6103e20c in mktime ()
(gdb) bt
#0 0x6103e20c in mktime ()
#1 0x6103ec46 in free ()
#2 0x610a999c in fclose ()
#3 0x00401600 in load_jump_table () at main.c:121
#4 0x004016b9 in main (argc=1, argv=0xa043180) at main.c:132
Any thoughts? Is this a bug?
|
|
|
|
06-27-2003, 11:22 AM
|
#2
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
Assuming there's no "free jt_file" somewhere in the <SNIP>ed parts (or in functions called there), it sounds like a bug.
|
|
|
|
06-27-2003, 11:52 AM
|
#3
|
|
Member
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488
Original Poster
Rep:
|
even if there were fclose (jt_file); lines in the <SNIP>'s (there's not), wouldn't this line not try to free it again?
if (jt_file) fclose(jt_file); /* this friggin' line */
from my understanding fclose resets the file handle to NULL after it closes it.
anyways, i just left the line commented and continued as normal ..... it was stupid program anyways ... computer-generated poetry  . Here's some output:
Code:
bash-2.05b$ cpoetry.exe
consolable masochism,
preliterate nonclassical,
chaffe methyltestosterone,
transsexual gambado,
telethermometer cothurnus unstartling;
subtrahend respite horresco,
slacks leptodactylus,
thews lobectomy,
sulla corruptness sphacelation,
serrate opisthobranchia prevents;
|
|
|
|
06-28-2003, 12:18 PM
|
#4
|
|
Member
Registered: Jun 2002
Location: Australia
Distribution: Slack 9.1
Posts: 232
Rep:
|
Not much help I know
This is probably irrelevant but the jt_file was never opened for writing, only reading, in contradiction to your error message.
Something more helpful, perhaps if you are reading past the EOF you subsequently cause segfault in fclose.
|
|
|
|
06-28-2003, 07:30 PM
|
#5
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
Quote:
even if there were fclose (jt_file); lines in the <SNIP>'s (there's not), wouldn't this line not try to free it again?
if (jt_file) fclose(jt_file); /* this friggin' line */
|
The stack backtrace you posted makes makes me think that it does try to free it again:
Quote:
#1 0x6103ec46 in free ()
#2 0x610a999c in fclose ()
|
Quote:
|
from my understanding fclose resets the file handle to NULL after it closes it.
|
I'm not sure about that. My man page (debian sarge) doesn't mention NULL, but says:
Quote:
|
In either case any further access (including another call to fclose()) to the stream results in undefined behaviour.
|
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:36 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|