diff options
author | Timo Sirainen <cras@irssi.org> | 2000-12-16 23:38:12 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-12-16 23:38:12 +0000 |
commit | fbad9ef2ba71e8b2baf5ed45995e2d44f43637e8 (patch) | |
tree | 180eec092df99e1faf411a4de18aba6bf06710eb /src/lib-config/write.c | |
parent | 2e033b5c6d83481f37cdb6531850388015c0e417 (diff) | |
download | irssi-fbad9ef2ba71e8b2baf5ed45995e2d44f43637e8.zip |
Config file handle wasn't closed if config_write_block() failed
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@993 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/lib-config/write.c')
-rw-r--r-- | src/lib-config/write.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lib-config/write.c b/src/lib-config/write.c index 76f29a09..bad7e878 100644 --- a/src/lib-config/write.c +++ b/src/lib-config/write.c @@ -310,10 +310,15 @@ static int config_write_block(CONFIG_REC *rec, CONFIG_NODE *node, int list, int /* Write configuration file. Write to `fname' if it's not NULL. */ int config_write(CONFIG_REC *rec, const char *fname, int create_mode) { + int ret; + g_return_val_if_fail(rec != NULL, -1); g_return_val_if_fail(fname != NULL || rec->fname != NULL, -1); g_return_val_if_fail(create_mode != -1 || rec->create_mode != -1, -1); + if (rec->handle != -1) + close(rec->handle); + rec->handle = open(fname != NULL ? fname : rec->fname, O_WRONLY | O_TRUNC | O_CREAT, create_mode != -1 ? create_mode : rec->create_mode); @@ -322,14 +327,14 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode) rec->tmp_indent_level = 0; rec->tmp_last_lf = TRUE; - if (config_write_block(rec, rec->mainnode, FALSE, TRUE) == -1) { + ret = config_write_block(rec, rec->mainnode, FALSE, TRUE); + if (ret == -1) { /* write error */ config_error(rec, errno == 0 ? "bug" : g_strerror(errno)); - return -1; } close(rec->handle); rec->handle = -1; - return 0; + return ret; } |