[srvx-commits] commit: More allocation debugging support.
Brought to you by:
entrope
|
From: Michael P. <md...@tr...> - 2005-01-24 16:46:30
|
Revision: srvx--devo--1.3--patch-7
Archive: sr...@sr...--2005-srvx
Creator: Michael Poole <md...@tr...>
Date: Mon Jan 24 11:45:44 EST 2005
Standard-date: 2005-01-24 16:45:44 GMT
Modified-files: ChangeLog src/alloc-srvx.c src/common.h
src/dict-splay.c src/hash.c src/mod-sockcheck.c
src/proto-p10.c
New-patches: sr...@sr...--2005-srvx/srvx--devo--1.3--patch-7
Summary: More allocation debugging support.
Keywords:
src/alloc-srvx.c (srvx_realloc): Reorganize.
(verify): New function.
src/common.h (verify): Define and/or declare suitably.
src/dict-splay.c (dict_splay): Verify node at each iteration.
(dict_insert, dict_remove2, dict_find, dict_delete,
dict_sanity_check): Verify entire dict.
(dict_sanity_check_node): Verify node as valid allocation.
src/hash.c (DelChannel): Verify channel before deletion.
(GetUserMode): Verify channel, user, and each modeNode.
src/mod-sockcheck.c (sockcheck_free_client): Verify client.
(sockcheck_timeout_client, sockcheck_advance, sockcheck_readable,
sockcheck_connected, sockcheck_begin_test): Likewise.
(sockcheck_queue_address): Verify cached sockcheck entries.
src/proto-p10.c (DelUser): Verify user before deletion.
* added files
{arch}/srvx/srvx--devo/srvx--devo--1.3/sr...@sr...--2005-srvx/patch-log/patch-7
* modified files
--- orig/ChangeLog
+++ mod/ChangeLog
@@ -2,6 +2,38 @@
# arch-tag: aut...@sr...--2005-srvx/srvx--devo--1.3
#
+2005-01-24 16:45:44 GMT Michael Poole <md...@tr...> patch-7
+
+ Summary:
+ More allocation debugging support.
+ Revision:
+ srvx--devo--1.3--patch-7
+
+ src/alloc-srvx.c (srvx_realloc): Reorganize.
+ (verify): New function.
+
+ src/common.h (verify): Define and/or declare suitably.
+
+ src/dict-splay.c (dict_splay): Verify node at each iteration.
+ (dict_insert, dict_remove2, dict_find, dict_delete,
+ dict_sanity_check): Verify entire dict.
+ (dict_sanity_check_node): Verify node as valid allocation.
+
+ src/hash.c (DelChannel): Verify channel before deletion.
+ (GetUserMode): Verify channel, user, and each modeNode.
+
+ src/mod-sockcheck.c (sockcheck_free_client): Verify client.
+ (sockcheck_timeout_client, sockcheck_advance, sockcheck_readable,
+ sockcheck_connected, sockcheck_begin_test): Likewise.
+ (sockcheck_queue_address): Verify cached sockcheck entries.
+
+ src/proto-p10.c (DelUser): Verify user before deletion.
+
+ modified files:
+ ChangeLog src/alloc-srvx.c src/common.h src/dict-splay.c
+ src/hash.c src/mod-sockcheck.c src/proto-p10.c
+
+
2005-01-21 15:10:49 GMT Michael Poole <md...@tr...> patch-6
Summary:
--- orig/src/alloc-srvx.c
+++ mod/src/alloc-srvx.c
@@ -74,19 +74,22 @@
void *
srvx_realloc(const char *file, unsigned int line, void *ptr, size_t size)
{
- struct alloc_header *block = NULL, *newblock;
+ struct alloc_header *block, *newblock;
- if (ptr) {
- block = (struct alloc_header *)ptr - 1;
- assert(block->magic == ALLOC_MAGIC);
- assert(0 == memcmp((char*)(block + 1) + block->size, redzone, sizeof(redzone)));
- if (block->size >= size)
- return block + 1;
- }
+ if (!ptr)
+ return srvx_malloc(file, line, size);
+
+ verify(ptr);
+ block = (struct alloc_header *)ptr - 1;
+
+ if (block->size >= size)
+ return block + 1;
newblock = malloc(sizeof(*newblock) + size + sizeof(redzone));
assert(newblock != NULL);
- memset(newblock, 0, sizeof(*newblock) + size + sizeof(redzone));
+ memset(newblock, 0, sizeof(*newblock));
+ memcpy(newblock + 1, block + 1, block->size);
+ memset((char*)(newblock + 1) + block->size, 0, size - block->size);
memcpy((char*)(newblock + 1) + size, redzone, sizeof(redzone));
newblock->file_id = get_file_id(file);
newblock->line = line;
@@ -95,15 +98,7 @@
alloc_count++;
alloc_size += size;
- if (ptr) {
- memcpy(newblock + 1, block + 1, block->size);
- size = block->size + sizeof(*block);
- memset(block, 0, size);
- block->magic = FREE_MAGIC;
- free(block);
- alloc_count--;
- alloc_size -= size - sizeof(*block);
- }
+ srvx_free(block);
return newblock + 1;
}
@@ -139,3 +134,14 @@
alloc_size -= size;
(void)file; (void)line;
}
+
+void
+verify(const void *ptr)
+{
+ const struct alloc_header *header;
+ if (!ptr)
+ return;
+ header = (const struct alloc_header*)ptr - 1;
+ assert(header->magic == ALLOC_MAGIC);
+ assert(!memcmp((char*)(header + 1) + header->size, redzone, sizeof(redzone)));
+}
--- orig/src/common.h
+++ mod/src/common.h
@@ -98,6 +98,14 @@
extern void *srvx_realloc(const char *, unsigned int, void *, size_t);
extern char *srvx_strdup(const char *, unsigned int, const char *);
extern void srvx_free(const char *, unsigned int, void *);
+# if !defined(NDEBUG)
+extern void verify(const void *ptr);
+# define verify(x) verify(x)
+# endif
+#endif
+
+#ifndef verify
+# define verify(ptr) (void)(ptr)
#endif
extern time_t now;
--- orig/src/dict-splay.c
+++ mod/src/dict-splay.c
@@ -75,12 +75,15 @@
dict_splay(struct dict_node *node, const char *key)
{
struct dict_node N, *l, *r, *y;
+ int res;
+
if (!node) return NULL;
N.l = N.r = NULL;
l = r = &N;
while (1) {
- int res = irccasecmp(key, node->key);
+ verify(node);
+ res = irccasecmp(key, node->key);
if (!res) break;
if (res < 0) {
if (!node->l) break;
@@ -149,6 +152,7 @@
struct dict_node *new_node;
if (!key)
return;
+ verify(dict);
new_node = malloc(sizeof(struct dict_node));
new_node->key = key;
new_node->data = data;
@@ -224,6 +228,7 @@
if (!dict->root)
return 0;
+ verify(dict);
dict->root = dict_splay(dict->root, key);
if (irccasecmp(key, dict->root->key))
return 0;
@@ -264,6 +269,7 @@
*found = 0;
return NULL;
}
+ verify(dict);
dict->root = dict_splay(dict->root, key);
was_found = !irccasecmp(key, dict->root->key);
if (found)
@@ -280,6 +286,7 @@
dict_iterator_t it, next;
if (!dict)
return;
+ verify(dict);
for (it=dict_first(dict); it; it=next) {
next = iter_next(it);
dict_dispose_node(it, dict->free_keys, dict->free_data);
@@ -296,6 +303,7 @@
static int
dict_sanity_check_node(struct dict_node *node, struct dict_sanity_struct *dss)
{
+ verify(node);
if (!node->key) {
snprintf(dss->error, sizeof(dss->error), "Node %p had null key", node);
return 1;
@@ -328,6 +336,7 @@
dss.node_count = 0;
dss.bad_node = 0;
dss.error[0] = 0;
+ verify(dict);
if (dict->root && dict_sanity_check_node(dict->root, &dss)) {
return strdup(dss.error);
} else if (dss.node_count != dict->count) {
--- orig/src/hash.c
+++ mod/src/hash.c
@@ -425,6 +425,7 @@
{
unsigned int n;
+ verify(channel);
dict_remove(channels, channel->name);
if (channel->members.used || channel->locks) {
@@ -691,8 +692,12 @@
{
unsigned int n;
struct modeNode *mn = NULL;
+
+ verify(channel);
+ verify(user);
if (channel->members.used < user->channels.used) {
for (n=0; n<channel->members.used; n++) {
+ verify(channel->members.list[n]);
if (user == channel->members.list[n]->user) {
mn = channel->members.list[n];
break;
@@ -700,6 +705,7 @@
}
} else {
for (n=0; n<user->channels.used; n++) {
+ verify(user->channels.list[n]);
if (channel == user->channels.list[n]->channel) {
mn = user->channels.list[n];
break;
--- orig/src/mod-sockcheck.c
+++ mod/src/mod-sockcheck.c
@@ -230,7 +230,9 @@
if (SOCKCHECK_DEBUG) {
log_module(PC_LOG, LOG_INFO, "Goodbye %s (%p)! I set you free!", client->addr->hostname, client);
}
- if (client->fd) ioset_close(client->fd->fd, 1);
+ verify(client);
+ if (client->fd)
+ ioset_close(client->fd->fd, 1);
sockcheck_list_unref(client->tests);
free(client->read);
free(client->resp_state);
@@ -248,6 +250,7 @@
if (SOCKCHECK_DEBUG) {
log_module(PC_LOG, LOG_INFO, "Client %s timed out.", client->addr->hostname);
}
+ verify(client);
sockcheck_advance(client, client->state->responses.used-1);
}
@@ -472,6 +475,7 @@
{
struct sockcheck_state *ns;
+ verify(client);
timeq_del(0, sockcheck_timeout_client, client, TIMEQ_IGNORE_WHEN);
if (SOCKCHECK_DEBUG) {
unsigned int n, m;
@@ -522,6 +526,7 @@
unsigned int nn;
int res;
+ verify(client);
res = read(fd->fd, client->read + client->read_used, client->read_size - client->read_used);
if (res < 0) {
switch (res = errno) {
@@ -628,6 +633,7 @@
sockcheck_connected(struct io_fd *fd, int rc)
{
struct sockcheck_client *client = fd->data;
+ verify(client);
client->fd = fd;
switch (rc) {
default:
@@ -654,6 +660,7 @@
{
struct io_fd *io_fd;
+ verify(client);
if (client->fd) {
ioset_close(client->fd->fd, 1);
client->fd = NULL;
@@ -708,6 +715,7 @@
sci = dict_find(checked_ip_dict, ipstr, NULL);
if (sci) {
+ verify(sci);
switch (sci->decision) {
case CHECKING:
/* We are already checking this host. */
--- orig/src/proto-p10.c
+++ mod/src/proto-p10.c
@@ -1943,6 +1943,8 @@
{
unsigned int n;
+ verify(user);
+
/* mark them as dead, in case anybody cares */
user->dead = 1;
|