[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Try to find out early if buffers get trashed or double-freed.
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv28111/or
Modified Files:
buffers.c connection.c or.h
Log Message:
Try to find out early if buffers get trashed or double-freed.
Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- buffers.c 28 Feb 2004 19:14:11 -0000 1.66
+++ buffers.c 3 Mar 2004 22:49:15 -0000 1.67
@@ -6,7 +6,9 @@
#include "or.h"
+#define BUFFER_MAGIC 0xB0FFF312u
struct buf_t {
+ uint32_t magic; /* for debugging */
char *mem;
size_t len;
size_t datalen;
@@ -118,6 +120,7 @@
buf_t *buf_new_with_capacity(size_t size) {
buf_t *buf;
buf = (buf_t*)tor_malloc(sizeof(buf_t));
+ buf->magic = BUFFER_MAGIC;
buf->mem = (char *)tor_malloc(size);
buf->len = size;
buf->datalen = 0;
@@ -153,9 +156,10 @@
}
void buf_free(buf_t *buf) {
- assert(buf && buf->mem);
- free(buf->mem);
- free(buf);
+ assert_buf_ok(buf);
+ buf->magic = 0xDEADBEEF;
+ tor_free(buf->mem);
+ tor_free(buf);
}
/* read from socket s, writing onto end of buf.
@@ -576,6 +580,14 @@
}
}
+void assert_buf_ok(buf_t *buf)
+{
+ assert(buf);
+ assert(buf->magic == BUFFER_MAGIC);
+ assert(buf->mem);
+ assert(buf->datalen <= buf->len);
+}
+
/*
Local Variables:
mode:c
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -d -r1.174 -r1.175
--- connection.c 3 Mar 2004 08:46:18 -0000 1.174
+++ connection.c 3 Mar 2004 22:49:15 -0000 1.175
@@ -866,8 +866,8 @@
/* buffers */
if (!connection_is_listener(conn)) {
- assert(conn->inbuf);
- assert(conn->outbuf);
+ assert_buf_ok(conn->inbuf);
+ assert_buf_ok(conn->outbuf);
}
assert(!now || conn->timestamp_lastread <= now);
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.243
retrieving revision 1.244
diff -u -d -r1.243 -r1.244
--- or.h 3 Mar 2004 05:08:01 -0000 1.243
+++ or.h 3 Mar 2004 22:49:15 -0000 1.244
@@ -572,6 +572,8 @@
char **body_out, int max_bodylen);
int fetch_from_buf_socks(buf_t *buf, socks_request_t *req);
+void assert_buf_ok(buf_t *buf);
+
/********************************* circuit.c ***************************/
void circuit_add(circuit_t *circ);