[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Segmentation fault



On Mon, Feb 14, 2000 at 11:43:25AM -0800, davidturetsky wrote:
> 
> Thanks, dancer. BTW, what's wrong with your code sample? I can see this is
> going to be daunting!

It dies when it tries to fclose the NULL pointer (fopen returns NULL
when it fails). free causes no trouble since it does nothing with NULL
according to the manpage. i wonder why fclose doesn't handle the problem
more gracefully in the NULL case?

Anyway, s/fclose(f)/if(f) fclose(f);/ to fix it.

> ----- Original Message -----
> From: Junichi Uekawa <ti0113@mail4.doshisha.ac.jp>
> >
> > For example, this code segfaults on Linux, which used to work perfectly
> fine on MSC:
> >
> >
> > char * bitsofmemory = malloc (BIG_SIZE); FILE*f =fopen(FILENAME,
> ATTRIBUTE);
> > if (!(bitsofmemory && f)) {
> >    free(bitsofmemory); fclose(f) /* try to clean up and it dies...*/
                 Missing semicolon? ^
> >    return ERROR;
> > }


-- 
  finger for GPG public key.
  8 Jan 2000 - Old email addresses removed from key, new added

Attachment: pgpDCjlzuYCs4.pgp
Description: PGP signature


Reply to: