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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-26-2003, 04: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, 12:22 PM
|
#2
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
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, 12:52 PM
|
#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, 01: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, 08:30 PM
|
#5
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
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.
|
|
|
|
All times are GMT -5. The time now is 07:18 PM.
|
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
|
|