[dovecot-cvs] dovecot/src/lib buffer.c, 1.29, 1.30 buffer.h, 1.17,
1.18 file-cache.c, 1.10, 1.11 file-cache.h, 1.4, 1.5 hash.c,
1.23, 1.24 hash.h, 1.13, 1.14 ioloop-notify-dn.c, 1.12,
1.13 ioloop.c, 1.30, 1.31 ioloop.h, 1.15, 1.16 istream-limit.c,
1.17, 1.18 istream-seekable.c, 1.7, 1.8 istream.c, 1.32,
1.33 istream.h, 1.22, 1.23 lib-signals.c, 1.10,
1.11 module-dir.c, 1.11, 1.12 module-dir.h, 1.3,
1.4 ostream-crlf.c, 1.12, 1.13 ostream-file.c, 1.58,
1.59 ostream.c, 1.14, 1.15 ostream.h, 1.13, 1.14 str.c, 1.16,
1.17 str.h, 1.7, 1.8
cras at dovecot.org
cras at dovecot.org
Sat Jan 14 20:47:33 EET 2006
- Previous message: [dovecot-cvs] dovecot/src/lib-dict dict-client.c, 1.4,
1.5 dict-sql.c, 1.4, 1.5 dict.c, 1.4, 1.5 dict.h, 1.4, 1.5
- Next message: [dovecot-cvs] dovecot/src/lib-imap imap-base-subject.c, 1.11,
1.12 imap-bodystructure.c, 1.53, 1.54 imap-envelope.c, 1.34,
1.35 imap-match.c, 1.8, 1.9 imap-match.h, 1.6,
1.7 imap-parser.c, 1.51, 1.52 imap-parser.h, 1.21, 1.22
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv16037/lib
Modified Files:
buffer.c buffer.h file-cache.c file-cache.h hash.c hash.h
ioloop-notify-dn.c ioloop.c ioloop.h istream-limit.c
istream-seekable.c istream.c istream.h lib-signals.c
module-dir.c module-dir.h ostream-crlf.c ostream-file.c
ostream.c ostream.h str.c str.h
Log Message:
deinit, unref, destroy, close, free, etc. functions now take a pointer to
their data pointer, and set it to NULL. This makes double-frees less likely
to cause security holes.
Index: buffer.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- buffer.c 13 Jan 2006 20:26:01 -0000 1.29
+++ buffer.c 14 Jan 2006 18:47:22 -0000 1.30
@@ -113,20 +113,23 @@
return (buffer_t *)buf;
}
-void buffer_free(buffer_t *_buf)
+void _buffer_free(buffer_t **_buf)
{
- struct real_buffer *buf = (struct real_buffer *)_buf;
+ struct real_buffer *buf = (struct real_buffer *)*_buf;
+ *_buf = NULL;
if (buf->alloced)
p_free(buf->pool, buf->w_buffer);
p_free(buf->pool, buf);
}
-void *buffer_free_without_data(buffer_t *_buf)
+void *_buffer_free_without_data(buffer_t **_buf)
{
- struct real_buffer *buf = (struct real_buffer *)_buf;
+ struct real_buffer *buf = (struct real_buffer *)*_buf;
void *data;
+ *_buf = NULL;
+
data = buf->w_buffer;
p_free(buf->pool, buf);
return data;
Index: buffer.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- buffer.h 13 Jan 2006 20:26:01 -0000 1.17
+++ buffer.h 14 Jan 2006 18:47:22 -0000 1.18
@@ -27,10 +27,12 @@
buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size);
/* Free the memory used by buffer. Not needed if the memory is free'd
directly from the memory pool. */
-void buffer_free(buffer_t *buf);
+void _buffer_free(buffer_t **buf);
+#define buffer_free(buf) _buffer_free(&(buf))
/* Free the memory used by buffer structure, but return the buffer data
unfree'd. */
-void *buffer_free_without_data(buffer_t *buf);
+void *_buffer_free_without_data(buffer_t **buf);
+#define buffer_free_without_data(buf) _buffer_free_without_data(&(buf))
/* Reset the buffer. used size and it's contents are zeroed. */
void buffer_reset(buffer_t *buf);
Index: file-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/file-cache.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- file-cache.c 14 May 2005 12:05:50 -0000 1.10
+++ file-cache.c 14 Jan 2006 18:47:22 -0000 1.11
@@ -26,8 +26,12 @@
return cache;
}
-void file_cache_free(struct file_cache *cache)
+void file_cache_free(struct file_cache **_cache)
{
+ struct file_cache *cache = *_cache;
+
+ *_cache = NULL;
+
if (cache->mmap_base != NULL) {
if (munmap_anon(cache->mmap_base, cache->mmap_length) < 0)
i_error("munmap_anon() failed: %m");
Index: file-cache.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/file-cache.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- file-cache.h 7 Aug 2005 11:41:20 -0000 1.4
+++ file-cache.h 14 Jan 2006 18:47:22 -0000 1.5
@@ -4,7 +4,8 @@
/* Create a new file cache. It works very much like file-backed mmap()ed
memory, but it works more nicely with remote filesystems (no SIGBUS). */
struct file_cache *file_cache_new(int fd);
-void file_cache_free(struct file_cache *cache);
+/* Destroy the cache and set cache pointer to NULL. */
+void file_cache_free(struct file_cache **cache);
/* Change cached file descriptor. Invalidates the whole cache. */
void file_cache_set_fd(struct file_cache *cache, int fd);
Index: hash.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/hash.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- hash.c 13 Jan 2006 20:26:01 -0000 1.23
+++ hash.c 14 Jan 2006 18:47:22 -0000 1.24
@@ -103,8 +103,12 @@
}
}
-void hash_destroy(struct hash_table *table)
+void _hash_destroy(struct hash_table **_table)
{
+ struct hash_table *table = *_table;
+
+ *_table = NULL;
+
if (!table->node_pool->alloconly_pool) {
hash_destroy_nodes(table);
destroy_node_list(table, table->free_nodes);
Index: hash.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/hash.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- hash.h 13 Jan 2006 20:26:01 -0000 1.13
+++ hash.h 14 Jan 2006 18:47:22 -0000 1.14
@@ -15,8 +15,8 @@
struct hash_table *
hash_create(pool_t table_pool, pool_t node_pool, size_t initial_size,
hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb);
-void hash_destroy(struct hash_table *table);
-
+void _hash_destroy(struct hash_table **table);
+#define hash_destroy(table) _hash_destroy(&(table))
/* Remove all nodes from hash table. If free_collisions is TRUE, the
memory allocated from node_pool is freed, or discarded with
alloconly pools. */
Index: ioloop-notify-dn.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-notify-dn.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ioloop-notify-dn.c 13 Jan 2006 20:26:01 -0000 1.12
+++ ioloop-notify-dn.c 14 Jan 2006 18:47:22 -0000 1.13
@@ -143,10 +143,8 @@
p_free(ioloop->pool, io);
- if (ioloop->notifys == NULL) {
- io_remove(ctx->event_io);
- ctx->event_io = NULL;
- }
+ if (ioloop->notifys == NULL)
+ io_remove(&ctx->event_io);
}
void io_loop_notify_handler_init(struct ioloop *ioloop)
Index: ioloop.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- ioloop.c 13 Jan 2006 20:26:01 -0000 1.30
+++ ioloop.c 14 Jan 2006 18:47:22 -0000 1.31
@@ -56,8 +56,12 @@
return io;
}
-void io_remove(struct io *io)
+void io_remove(struct io **_io)
{
+ struct io *io = *_io;
+
+ *_io = NULL;
+
if ((io->condition & IO_NOTIFY) != 0) {
io_loop_notify_remove(current_ioloop, io);
return;
@@ -134,11 +138,12 @@
return timeout;
}
-void timeout_remove(struct timeout *timeout)
+void timeout_remove(struct timeout **timeout)
{
- i_assert(timeout != NULL);
+ i_assert(*timeout != NULL);
- timeout->destroyed = TRUE;
+ (*timeout)->destroyed = TRUE;
+ *timeout = NULL;
}
void timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p)
@@ -267,15 +272,18 @@
return ioloop;
}
-void io_loop_destroy(struct ioloop *ioloop)
+void io_loop_destroy(struct ioloop **_ioloop)
{
+ struct ioloop *ioloop = *_ioloop;
pool_t pool;
+ *_ioloop = NULL;
+
while (ioloop->ios != NULL) {
struct io *io = ioloop->ios;
i_warning("I/O leak: %p (%d)", (void *)io->callback, io->fd);
- io_remove(io);
+ io_remove(&io);
}
while (ioloop->timeouts != NULL) {
@@ -283,7 +291,7 @@
if (!to->destroyed) {
i_warning("Timeout leak: %p", (void *)to->callback);
- timeout_remove(to);
+ timeout_remove(&to);
}
timeout_destroy(ioloop, &ioloop->timeouts);
}
Index: ioloop.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- ioloop.h 13 Jan 2006 20:26:01 -0000 1.15
+++ ioloop.h 14 Jan 2006 18:47:22 -0000 1.16
@@ -37,12 +37,14 @@
io_callback_t *callback, void *context);
struct io *io_add_notify(const char *path, io_callback_t *callback,
void *context);
-void io_remove(struct io *io);
+/* Remove I/O handler, and set io pointer to NULL. */
+void io_remove(struct io **io);
/* Timeout handlers */
struct timeout *timeout_add(unsigned int msecs, timeout_callback_t *callback,
void *context);
-void timeout_remove(struct timeout *timeout);
+/* Remove timeout handler, and set timeout pointer to NULL. */
+void timeout_remove(struct timeout **timeout);
void io_loop_run(struct ioloop *ioloop);
void io_loop_stop(struct ioloop *ioloop); /* safe to run in signal handler */
@@ -54,6 +56,7 @@
void io_loop_handler_run(struct ioloop *ioloop);
struct ioloop *io_loop_create(pool_t pool);
-void io_loop_destroy(struct ioloop *ioloop);
+/* Destroy I/O loop and set ioloop pointer to NULL. */
+void io_loop_destroy(struct ioloop **ioloop);
#endif
Index: istream-limit.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-limit.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- istream-limit.c 13 Jan 2006 20:26:01 -0000 1.17
+++ istream-limit.c 14 Jan 2006 18:47:22 -0000 1.18
@@ -21,7 +21,7 @@
/* get to same position in parent stream */
i_stream_seek(lstream->input, lstream->v_start_offset +
lstream->istream.istream.v_offset);
- i_stream_unref(lstream->input);
+ i_stream_unref(&lstream->input);
}
static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
Index: istream-seekable.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-seekable.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- istream-seekable.c 13 Jan 2006 20:26:01 -0000 1.7
+++ istream-seekable.c 14 Jan 2006 18:47:22 -0000 1.8
@@ -50,9 +50,9 @@
if (sstream->buffer != NULL)
buffer_free(sstream->buffer);
if (sstream->fd_input != NULL)
- i_stream_unref(sstream->fd_input);
+ i_stream_unref(&sstream->fd_input);
for (i = 0; sstream->input[i] != NULL; i++)
- i_stream_unref(sstream->input[i]);
+ i_stream_unref(&sstream->input[i]);
p_free(sstream->pool, sstream->temp_prefix);
pool_unref(sstream->pool);
Index: istream.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- istream.c 13 Jan 2006 20:26:01 -0000 1.32
+++ istream.c 14 Jan 2006 18:47:22 -0000 1.33
@@ -10,15 +10,16 @@
_io_stream_ref(&stream->real_stream->iostream);
}
-void i_stream_unref(struct istream *stream)
+void i_stream_unref(struct istream **stream)
{
- struct _istream *_stream = stream->real_stream;
+ struct _istream *_stream = (*stream)->real_stream;
if (_stream->iostream.refcount == 1) {
if (_stream->line_str != NULL)
- str_free(_stream->line_str);
+ str_free(&_stream->line_str);
}
- _io_stream_unref(&stream->real_stream->iostream);
+ _io_stream_unref(&(*stream)->real_stream->iostream);
+ *stream = NULL;
}
int i_stream_get_fd(struct istream *stream)
Index: istream.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- istream.h 13 Jan 2006 20:26:01 -0000 1.22
+++ istream.h 14 Jan 2006 18:47:22 -0000 1.23
@@ -27,7 +27,8 @@
/* Reference counting. References start from 1, so calling i_stream_unref()
destroys the stream if i_stream_ref() is never used. */
void i_stream_ref(struct istream *stream);
-void i_stream_unref(struct istream *stream);
+/* Unreferences the stream and sets stream pointer to NULL. */
+void i_stream_unref(struct istream **stream);
/* Return file descriptor for stream, or -1 if none is available. */
int i_stream_get_fd(struct istream *stream);
Index: lib-signals.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/lib-signals.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- lib-signals.c 13 Jan 2006 20:26:01 -0000 1.10
+++ lib-signals.c 14 Jan 2006 18:47:22 -0000 1.11
@@ -186,7 +186,7 @@
}
if (io_sig != NULL)
- io_remove(io_sig);
+ io_remove(&io_sig);
if (sig_pipe_fd[0] != -1) {
if (close(sig_pipe_fd[0]) < 0)
i_error("close(sigpipe) failed: %m");
Index: module-dir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- module-dir.c 13 Jan 2006 20:26:01 -0000 1.11
+++ module-dir.c 14 Jan 2006 18:47:22 -0000 1.12
@@ -187,15 +187,16 @@
return modules;
}
-void module_dir_unload(struct module *modules)
+void module_dir_unload(struct module **modules)
{
- struct module *next;
+ struct module *module, *next;
- while (modules != NULL) {
- next = modules->next;
- module_free(modules);
- modules = next;
+ for (module = *modules; module != NULL; module = next) {
+ next = module->next;
+ module_free(module);
}
+
+ *modules = NULL;
}
#else
Index: module-dir.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- module-dir.h 13 Jan 2006 20:26:01 -0000 1.3
+++ module-dir.h 14 Jan 2006 18:47:22 -0000 1.4
@@ -13,7 +13,7 @@
/* Load all modules in given directory. */
struct module *module_dir_load(const char *dir, bool require_init_funcs);
/* Unload all modules */
-void module_dir_unload(struct module *modules);
+void module_dir_unload(struct module **modules);
void *module_get_symbol(struct module *module, const char *symbol);
Index: ostream-crlf.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-crlf.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ostream-crlf.c 13 Jan 2006 20:26:01 -0000 1.12
+++ ostream-crlf.c 14 Jan 2006 18:47:22 -0000 1.13
@@ -28,7 +28,7 @@
{
struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
- o_stream_unref(cstream->output);
+ o_stream_unref(&cstream->output);
}
static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
Index: ostream-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-file.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- ostream-file.c 13 Jan 2006 20:26:01 -0000 1.58
+++ ostream-file.c 14 Jan 2006 18:47:22 -0000 1.59
@@ -57,10 +57,8 @@
fstream->fd = -1;
}
- if (fstream->io != NULL) {
- io_remove(fstream->io);
- fstream->io = NULL;
- }
+ if (fstream->io != NULL)
+ io_remove(&fstream->io);
fstream->ostream.ostream.closed = TRUE;
}
@@ -215,10 +213,9 @@
int ret;
if (fstream->corked != set && !stream->ostream.closed) {
- if (set && fstream->io != NULL) {
- io_remove(fstream->io);
- fstream->io = NULL;
- } else if (!set) {
+ if (set && fstream->io != NULL)
+ io_remove(&fstream->io);
+ else if (!set) {
ret = buffer_flush(fstream);
if (fstream->io == NULL &&
(ret == 0 || fstream->flush_pending)) {
@@ -343,6 +340,7 @@
static void stream_send_io(void *context)
{
struct file_ostream *fstream = context;
+ struct ostream *ostream = &fstream->ostream.ostream;
int ret;
/* Set flush_pending = FALSE first before calling the flush callback,
@@ -351,7 +349,7 @@
forget it even if flush callback returns 1. */
fstream->flush_pending = FALSE;
- o_stream_ref(&fstream->ostream.ostream);
+ o_stream_ref(ostream);
if (fstream->ostream.callback != NULL)
ret = fstream->ostream.callback(fstream->ostream.context);
else
@@ -363,8 +361,7 @@
if (!fstream->flush_pending && IS_STREAM_EMPTY(fstream)) {
if (fstream->io != NULL) {
/* all sent */
- io_remove(fstream->io);
- fstream->io = NULL;
+ io_remove(&fstream->io);
}
} else {
/* Add the IO handler if it's not there already. Callback
@@ -376,7 +373,7 @@
}
}
- o_stream_unref(&fstream->ostream.ostream);
+ o_stream_unref(&ostream);
}
static size_t o_stream_add(struct file_ostream *fstream,
Index: ostream.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ostream.c 13 Jan 2006 20:26:01 -0000 1.14
+++ ostream.c 14 Jan 2006 18:47:22 -0000 1.15
@@ -9,9 +9,10 @@
_io_stream_ref(&stream->real_stream->iostream);
}
-void o_stream_unref(struct ostream *stream)
+void o_stream_unref(struct ostream **stream)
{
- _io_stream_unref(&stream->real_stream->iostream);
+ _io_stream_unref(&(*stream)->real_stream->iostream);
+ *stream = NULL;
}
void o_stream_close(struct ostream *stream)
Index: ostream.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- ostream.h 13 Jan 2006 20:26:01 -0000 1.13
+++ ostream.h 14 Jan 2006 18:47:22 -0000 1.14
@@ -30,7 +30,8 @@
/* Reference counting. References start from 1, so calling o_stream_unref()
destroys the stream if o_stream_ref() is never used. */
void o_stream_ref(struct ostream *stream);
-void o_stream_unref(struct ostream *stream);
+/* Unreferences the stream and sets stream pointer to NULL. */
+void o_stream_unref(struct ostream **stream);
/* Mark the stream closed. Nothing will be sent after this call. */
void o_stream_close(struct ostream *stream);
Index: str.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/str.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- str.c 1 Nov 2004 12:15:42 -0000 1.16
+++ str.c 14 Jan 2006 18:47:22 -0000 1.17
@@ -17,9 +17,9 @@
return str_new(pool_datastack_create(), initial_size);
}
-void str_free(string_t *str)
+void str_free(string_t **str)
{
- buffer_free(str);
+ buffer_free(*str);
}
static void str_add_nul(string_t *str)
@@ -33,10 +33,10 @@
buffer_set_used_size(str, len);
}
-char *str_free_without_data(string_t *str)
+char *str_free_without_data(string_t **str)
{
- str_add_nul(str);
- return buffer_free_without_data(str);
+ str_add_nul(*str);
+ return buffer_free_without_data(*str);
}
const char *str_c(string_t *str)
Index: str.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/str.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- str.h 1 Nov 2004 12:15:42 -0000 1.7
+++ str.h 14 Jan 2006 18:47:22 -0000 1.8
@@ -3,8 +3,8 @@
string_t *str_new(pool_t pool, size_t initial_size);
string_t *t_str_new(size_t initial_size);
-void str_free(string_t *str);
-char *str_free_without_data(string_t *str);
+void str_free(string_t **str);
+char *str_free_without_data(string_t **str);
const char *str_c(string_t *str);
const unsigned char *str_data(const string_t *str);
- Previous message: [dovecot-cvs] dovecot/src/lib-dict dict-client.c, 1.4,
1.5 dict-sql.c, 1.4, 1.5 dict.c, 1.4, 1.5 dict.h, 1.4, 1.5
- Next message: [dovecot-cvs] dovecot/src/lib-imap imap-base-subject.c, 1.11,
1.12 imap-bodystructure.c, 1.53, 1.54 imap-envelope.c, 1.34,
1.35 imap-match.c, 1.8, 1.9 imap-match.h, 1.6,
1.7 imap-parser.c, 1.51, 1.52 imap-parser.h, 1.21, 1.22
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list