diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-06-04 17:18:30 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2024-06-04 17:18:30 -0400 |
commit | 1b7d35126b1093f54f228384d1d19c066c9b9a9c (patch) | |
tree | 7a7431ec9cb762b9376c6e4721bf018d76c99a9c | |
parent | dad01f29ff04772151d614781f1bb93b55ca1af2 (diff) | |
download | rockbox-1b7d35126b.tar.gz rockbox-1b7d35126b.zip |
[coverity] playlist.c pl_save_update_control fix rest of potential fd leaks
Change-Id: I65a8ac6a2ce68c5fd3cde570c3ff1b2e737d911d
-rw-r--r-- | apps/playlist.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 7040c2a129..77e0ee4370 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -3894,7 +3894,7 @@ static int pl_save_update_control(struct playlist_info* playlist, char *tmpbuf, size_t tmpsize) { int old_fd; - int err; + int err = 0; char c; bool any_queued = false; @@ -3915,8 +3915,8 @@ static int pl_save_update_control(struct playlist_info* playlist, playlist->control_fd = open(tmpbuf, O_CREAT|O_RDWR|O_TRUNC, 0666); if (playlist->control_fd < 0) { - close(old_fd); - return -3; + err = -3; + goto error; } /* Write out playlist filename */ @@ -3932,8 +3932,8 @@ static int pl_save_update_control(struct playlist_info* playlist, if (err <= 0) { - close(old_fd); - return -4; + err = -4; + goto error; } if (playlist->first_index > 0) @@ -3964,8 +3964,10 @@ static int pl_save_update_control(struct playlist_info* playlist, index, playlist->last_insert_pos, tmpbuf, NULL, &seekpos); if (err <= 0) - return -5; - + { + err = -5; + goto error; + } /* Update seek offset for the new control file. */ playlist->indices[index] &= ~PLAYLIST_SEEK_MASK; playlist->indices[index] |= seekpos; @@ -3980,7 +3982,10 @@ static int pl_save_update_control(struct playlist_info* playlist, err = update_control_unlocked(playlist, PLAYLIST_COMMAND_FLAGS, PLAYLIST_FLAG_MODIFIED, 0, NULL, NULL, NULL); if (err <= 0) - return -6; + { + err = -6; + goto error; + } } else { @@ -4006,7 +4011,12 @@ static int pl_save_update_control(struct playlist_info* playlist, playlist->control_fd = open(playlist->control_filename, O_RDWR); playlist->control_created = (playlist->control_fd >= 0); + return 0; + +error: + close(old_fd); + return err; } int playlist_save(struct playlist_info* playlist, char *filename) |