Skip to content

Redis 6.0 use double fclose in rdb.c #7256

@luoyuyan

Description

@luoyuyan

https://github.com/antirez/redis/blob/8f5c2bc8aa79985f6767e4847cc5a5d9606b1b5c/src/rdb.c#L1307

in rdbSave(char *filename, rdbSaveInfo *rsi),
If first fclose() return EOF, function goto werr, excute fclose() again.

But the Linux Programmer's Manual indicate that any further access (including another call to fclose()) to the stream results in undefined behavior.

It is possible that A segfault or any error occurred.

Linux Programmer's Manual

FCLOSE(3) Linux Programmer's Manual FCLOSE(3)

NAME
fclose - close a stream

SYNOPSIS
#include <stdio.h>

   int fclose(FILE *stream);

DESCRIPTION
The fclose() function flushes the stream pointed to by stream (writing
any buffered output data using fflush(3)) and closes the underlying
file descriptor.

   The  behaviour  of  fclose() is undefined if the stream parameter is an
   illegal pointer, or is a descriptor already passed to a previous  invo‐
   cation of fclose().

RETURN VALUE
Upon successful completion 0 is returned. Otherwise, EOF is returned
and errno is set to indicate the error. In either case any further
access (including another call to fclose()) to the stream results in
undefined behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions