From 10e951eb2ea5fc1230418cb9a933549771117d05 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Fri, 6 Nov 2020 00:39:39 +0000 Subject: [PATCH] fix bug in tfile --- src/util/src/tfile.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/util/src/tfile.c b/src/util/src/tfile.c index ea699c2436..c3becef82c 100644 --- a/src/util/src/tfile.c +++ b/src/util/src/tfile.c @@ -26,13 +26,11 @@ static void taosCloseFile(void *p) { } int tfinit() { - tsFileRsetId = taosOpenRef(2000, taosCloseFile); return tsFileRsetId; } void tfcleanup() { - if (tsFileRsetId >= 0) taosCloseRef(tsFileRsetId); tsFileRsetId = -1; } @@ -45,17 +43,15 @@ int64_t tfopen(const char *pathname, int flags) { return -1; } - int64_t rid = taosAddRef(tsFileRsetId, (void *)(long)fd); - if (rid < 0) { - close(fd); - return -1; - } + void *p = (void *)(long)fd; + int64_t rid = taosAddRef(tsFileRsetId, p); + if (rid < 0) close(fd); return rid; } int64_t tfclose(int64_t tfd) { - return taosReleaseRef(tsFileRsetId, tfd); + return taosRemoveRef(tsFileRsetId, tfd); } ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) { @@ -66,10 +62,7 @@ ssize_t tfwrite(int64_t tfd, const void *buf, size_t count) { int fd = (int)(uintptr_t)p; ssize_t ret = write(fd, buf, count); - if (ret < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } + if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno); taosReleaseRef(tsFileRsetId, tfd); return ret; @@ -83,10 +76,7 @@ ssize_t tfread(int64_t tfd, void *buf, size_t count) { int fd = (int)(uintptr_t)p; ssize_t ret = read(fd, buf, count); - if (ret < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } + if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno); taosReleaseRef(tsFileRsetId, tfd); return ret; -- GitLab