Initialize fd to invalid '-1' and remove unnecessary file_opened.
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
int save_session(struct ltt_session *session,
struct lttng_save_session_attr *attr, lttng_sock_cred *creds)
{
int save_session(struct ltt_session *session,
struct lttng_save_session_attr *attr, lttng_sock_cred *creds)
{
- int ret, fd;
- unsigned int file_opened = 0; /* Indicate if the file has been opened */
char config_file_path[PATH_MAX];
size_t len;
struct config_writer *writer = NULL;
char config_file_path[PATH_MAX];
size_t len;
struct config_writer *writer = NULL;
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
writer = config_writer_create(fd, 1);
if (!writer) {
writer = config_writer_create(fd, 1);
if (!writer) {
}
if (ret) {
/* Delete file in case of error */
}
if (ret) {
/* Delete file in case of error */
- if (file_opened && unlink(config_file_path)) {
+ if ((fd >= 0) && unlink(config_file_path)) {
PERROR("Unlinking XML session configuration.");
}
}
PERROR("Unlinking XML session configuration.");
}
}
ret = close(fd);
if (ret) {
PERROR("Closing XML session configuration");
ret = close(fd);
if (ret) {
PERROR("Closing XML session configuration");