CID 702036: catattr: close file descriptor after usage
This commit is contained in:
+8
-1
@@ -142,8 +142,10 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw,
|
|||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
attr_info info;
|
attr_info info;
|
||||||
if (fs_stat_attr(fd, attribute, &info) < 0)
|
if (fs_stat_attr(fd, attribute, &info) < 0) {
|
||||||
|
close(fd);
|
||||||
return errno;
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
// limit size of the attribute, only the first 64k will make it on screen
|
// limit size of the attribute, only the first 64k will make it on screen
|
||||||
off_t size = info.size;
|
off_t size = info.size;
|
||||||
@@ -156,12 +158,14 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw,
|
|||||||
char* buffer = (char*)malloc(size);
|
char* buffer = (char*)malloc(size);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
fprintf(stderr, "Could not allocate read buffer!\n");
|
fprintf(stderr, "Could not allocate read buffer!\n");
|
||||||
|
close(fd);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t bytesRead = fs_read_attr(fd, attribute, info.type, 0, buffer, size);
|
ssize_t bytesRead = fs_read_attr(fd, attribute, info.type, 0, buffer, size);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
close(fd);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +173,7 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw,
|
|||||||
fprintf(stderr, "Could only read %ld bytes from attribute!\n",
|
fprintf(stderr, "Could only read %ld bytes from attribute!\n",
|
||||||
bytesRead);
|
bytesRead);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
close(fd);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,6 +215,7 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw,
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
if (written > 0)
|
if (written > 0)
|
||||||
written = B_OK;
|
written = B_OK;
|
||||||
|
close(fd);
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +281,7 @@ catAttr(const char *attribute, const char *fileName, bool keepRaw,
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
close(fd);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user