Re: SIGSEGV on fclose.

From: Henning P. Schmiedehausen (hps@tanstaafl.de)
Date: Fri Jul 14 2000 - 09:56:40 EST


bbl@dk.damgaard.com (Bjarne Blichfeldt) writes:

>On linux I get a SIGSEGV, Segmentation fault if I close a nonopen file.

>On unix platforms, this is either simply ignored or an appropiate
>errormessage is returned, and according to the linux manualpage fclose
>on linux should return EBADF.

>I have testet the following example on AIX 4.3, Solaris 7, FreeBSD 4.0,
>TRU64, HPUX 10.20, SCO ODT5, linux kernel 2.2.15 and linux kernel
>2.2.13.

>in case you wonder: the problem arises from a program that closes a
>file twice because it does not know that the file is allready closed.

>Regards,
>Bjarne

>/*--------------------------------------------*/
>#include <stdio.h>

>FILE *new;

>main () {

> fclose (new); /* <---- SIGSEGV on linux only */
>}
>/*--------------------------------------------*/

[...]
        if(fd)
        {
                fclose(fd);
                fd = NULL;
        }
[...]

no problem with this. Make your own code more robust.

        Regards
                Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22 Fon.: 09131 / 50654-0 info@intermeta.de D-91054 Buckenhof Fax.: 09131 / 50654-20

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:20 EST