rdb.c: Avoid potential file handle leak (Coverity 404720) (#12795)

`open()` can return any non-negative integer on success, including zero.
This change modifies the check from open()'s return value to also
include checking for a return value of zero (e.g., if stdin were closed
and then `open()` was called).

Fixes Coverity 404720

Can't happen in Redis. just a cleanup.
This commit is contained in:
Moshe Kaplan 2023-11-23 03:14:17 -05:00 committed by GitHub
parent ae09d4d3ef
commit c9aa586b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3442,7 +3442,7 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) {
if (retval == C_OK && !(rdbflags & RDBFLAGS_KEEP_CACHE)) {
/* TODO: maybe we could combine the fopen and open into one in the future */
rdb_fd = open(filename, O_RDONLY);
if (rdb_fd > 0) bioCreateCloseJob(rdb_fd, 0, 1);
if (rdb_fd >= 0) bioCreateCloseJob(rdb_fd, 0, 1);
}
return (retval==C_OK) ? RDB_OK : RDB_FAILED;
}