[dovecot-cvs] dovecot/src/lib-index mail-transaction-log.c, 1.42,
1.43
cras at procontrol.fi
cras at procontrol.fi
Mon Jun 28 15:08:03 EEST 2004
Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv25353/lib-index
Modified Files:
mail-transaction-log.c
Log Message:
fixed some fd leaks in error conditions
Index: mail-transaction-log.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- mail-transaction-log.c 24 Jun 2004 11:10:41 -0000 1.42
+++ mail-transaction-log.c 28 Jun 2004 12:08:00 -0000 1.43
@@ -22,6 +22,8 @@
#define LOG_DOTLOCK_STALE_TIMEOUT 0
#define LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT 300
+#define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
+
struct mail_transaction_add_ctx {
struct mail_transaction_log *log;
struct mail_index_view *view;
@@ -342,27 +344,15 @@
}
static int
-mail_transaction_log_file_create(struct mail_transaction_log *log,
- const char *path, dev_t dev, ino_t ino)
+mail_transaction_log_file_create2(struct mail_transaction_log *log,
+ const char *path, int fd,
+ dev_t dev, ino_t ino)
{
-#define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
struct mail_index *index = log->index;
struct mail_transaction_log_header hdr;
struct stat st;
unsigned int lock_id;
- int fd, fd2, ret;
-
- /* With dotlocking we might already have path.lock created, so this
- filename has to be different. */
- fd = file_dotlock_open(path, NULL, LOG_NEW_DOTLOCK_SUFFIX,
- LOG_DOTLOCK_TIMEOUT,
- LOG_DOTLOCK_STALE_TIMEOUT,
- LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, NULL, NULL);
- if (fd == -1) {
- mail_index_file_set_syscall_error(index, path,
- "file_dotlock_open()");
- return -1;
- }
+ int fd2, ret;
/* log creation is locked now - see if someone already created it */
fd2 = open(path, O_RDWR);
@@ -411,14 +401,12 @@
if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
mail_index_file_set_syscall_error(index, path,
"write_full()");
- (void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);
return -1;
}
fd2 = dup(fd);
if (fd2 < 0) {
mail_index_file_set_syscall_error(index, path, "dup()");
- (void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);
return -1;
}
@@ -429,6 +417,32 @@
return fd2;
}
+static int
+mail_transaction_log_file_create(struct mail_transaction_log *log,
+ const char *path, dev_t dev, ino_t ino)
+{
+ int fd, fd2;
+
+ /* With dotlocking we might already have path.lock created, so this
+ filename has to be different. */
+ fd = file_dotlock_open(path, NULL, LOG_NEW_DOTLOCK_SUFFIX,
+ LOG_DOTLOCK_TIMEOUT,
+ LOG_DOTLOCK_STALE_TIMEOUT,
+ LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, NULL, NULL);
+ if (fd == -1) {
+ mail_index_file_set_syscall_error(log->index, path,
+ "file_dotlock_open()");
+ return -1;
+ }
+
+ fd2 = mail_transaction_log_file_create2(log, path, fd, dev, ino);
+ if (fd2 < 0) {
+ (void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);
+ return -1;
+ }
+ return fd2;
+}
+
static struct mail_transaction_log_file *
mail_transaction_log_file_fd_open(struct mail_transaction_log *log,
const char *path, int fd)
@@ -440,6 +454,7 @@
if (fstat(fd, &st) < 0) {
mail_index_file_set_syscall_error(log->index, path, "fstat()");
+ (void)close(fd);
return NULL;
}
More information about the dovecot-cvs
mailing list