[TD-2752]<fix>: check if the FILE pointer is valid or not.

This commit is contained in:
Haojun Liao 2021-01-14 16:18:37 +08:00
parent 52a524624d
commit bd99bde945
1 changed files with 4 additions and 3 deletions

View File

@ -6928,11 +6928,12 @@ static size_t getResultSize(SQInfo *pQInfo, int64_t *numOfRows) {
*/ */
if (isTSCompQuery(pQuery) && (*numOfRows) > 0) { if (isTSCompQuery(pQuery) && (*numOfRows) > 0) {
struct stat fStat; struct stat fStat;
if (fstat(fileno(*(FILE **)pQuery->sdata[0]->data), &fStat) == 0) { FILE *f = *(FILE **)pQuery->sdata[0]->data;
if ((f != NULL) && (fstat(fileno(f), &fStat) == 0)) {
*numOfRows = fStat.st_size; *numOfRows = fStat.st_size;
return fStat.st_size; return fStat.st_size;
} else { } else {
qError("QInfo:%p failed to get file info, path:%s, reason:%s", pQInfo, pQuery->sdata[0]->data, strerror(errno)); qError("QInfo:%p failed to get file info, file:%p, reason:%s", pQInfo, f, strerror(errno));
return 0; return 0;
} }
} else { } else {
@ -6947,7 +6948,7 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
// load data from file to msg buffer // load data from file to msg buffer
if (isTSCompQuery(pQuery)) { if (isTSCompQuery(pQuery)) {
FILE *f = *(FILE **)pQuery->sdata[0]->data; FILE *f = *(FILE **)pQuery->sdata[0]->data; // TODO refactor
// make sure file exist // make sure file exist
if (f) { if (f) {