The following commit has been merged in the master branch: commit 9449f4a0fd66e6b224587a9b15174ffd4905d60d Author: Marek Lindner lindner_marek@yahoo.de Date: Tue Jan 2 15:05:21 2007 +0100
allocate improved (free tags added)
diff --git a/allocate.c b/allocate.c index 71c14a5..e6ea113 100644 --- a/allocate.c +++ b/allocate.c @@ -35,7 +35,7 @@ void checkIntegrity(void) { if (walker->magicNumber != MAGIC_NUMBER) { - fprintf(stderr, "Invalid magic number in header: %08x, tag = %d\n", walker->magicNumber, walker->tag); + fprintf(stderr, "Invalid magic number in header: %08x, malloc tag = %d\n", walker->magicNumber, walker->tag); exit(1); }
@@ -45,7 +45,7 @@ void checkIntegrity(void)
if (chunkTrailer->magicNumber != MAGIC_NUMBER) { - fprintf(stderr, "Invalid magic number in header: %08x, tag = %d\n", chunkTrailer->magicNumber, walker->tag); + fprintf(stderr, "Invalid magic number in header: %08x, malloc tag = %d\n", chunkTrailer->magicNumber, walker->tag); exit(1); } } @@ -56,7 +56,7 @@ void checkLeak(void) struct chunkHeader *walker;
for (walker = chunkList; walker != NULL; walker = walker->next) - fprintf(stderr, "Memory leak detected, tag = %d\n", walker->tag); + fprintf(stderr, "Memory leak detected, malloc tag = %d\n", walker->tag); }
void *debugMalloc(unsigned int length, int tag) @@ -72,7 +72,7 @@ void *debugMalloc(unsigned int length, int tag)
if (memory == NULL) { - fprintf(stderr, "Cannot allocate %u bytes, tag = %d\n", (unsigned int)(length + sizeof(struct chunkHeader) + sizeof(struct chunkTrailer)), tag); + fprintf(stderr, "Cannot allocate %u bytes, malloc tag = %d\n", (unsigned int)(length + sizeof(struct chunkHeader) + sizeof(struct chunkTrailer)), tag); exit(1); }
@@ -103,22 +103,22 @@ void *debugRealloc(void *memoryParameter, unsigned int length, int tag) if (memoryParameter) { /* if memoryParameter==NULL, realloc() should work like malloc() !! */ memory = memoryParameter; chunkHeader = (struct chunkHeader *)(memory - sizeof(struct chunkHeader)); - + if (chunkHeader->magicNumber != MAGIC_NUMBER) { - fprintf(stderr, "Invalid magic number in header: %08x, tag = %d\n", chunkHeader->magicNumber, chunkHeader->tag); + fprintf(stderr, "Invalid magic number in header: %08x, malloc tag = %d\n", chunkHeader->magicNumber, chunkHeader->tag); exit(1); } - + chunkTrailer = (struct chunkTrailer *)(memory + chunkHeader->length); - + if (chunkTrailer->magicNumber != MAGIC_NUMBER) { - fprintf(stderr, "Invalid magic number in header: %08x, tag = %d\n", chunkTrailer->magicNumber, chunkHeader->tag); + fprintf(stderr, "Invalid magic number in header: %08x, malloc tag = %d\n", chunkTrailer->magicNumber, chunkHeader->tag); exit(1); } } - +
result = debugMalloc(length, tag); if (memoryParameter) { @@ -126,16 +126,16 @@ void *debugRealloc(void *memoryParameter, unsigned int length, int tag)
if (copyLength > chunkHeader->length) copyLength = chunkHeader->length; - + memcpy(result, memoryParameter, copyLength); - debugFree(memoryParameter); + debugFree(memoryParameter, 9999); }
return result; }
-void debugFree(void *memoryParameter) +void debugFree(void *memoryParameter, int tag) { unsigned char *memory; struct chunkHeader *chunkHeader; @@ -148,7 +148,7 @@ void debugFree(void *memoryParameter)
if (chunkHeader->magicNumber != MAGIC_NUMBER) { - fprintf(stderr, "Invalid magic number in header: %08x, tag = %d\n", chunkHeader->magicNumber, chunkHeader->tag); + fprintf(stderr, "Invalid magic number in header: %08x, malloc tag = %d, free tag = %d\n", chunkHeader->magicNumber, chunkHeader->tag, tag); exit(1); }
@@ -164,7 +164,7 @@ void debugFree(void *memoryParameter)
if (walker == NULL) { - fprintf(stderr, "Double free detected, tag = %d\n", chunkHeader->tag); + fprintf(stderr, "Double free detected, malloc tag = %d, free tag = %d\n", chunkHeader->tag, tag); exit(1); }
@@ -178,7 +178,7 @@ void debugFree(void *memoryParameter)
if (chunkTrailer->magicNumber != MAGIC_NUMBER) { - fprintf(stderr, "Invalid magic number in header: %08x, tag = %d\n", chunkTrailer->magicNumber, chunkHeader->tag); + fprintf(stderr, "Invalid magic number in header: %08x, malloc tag = %d, free tag = %d\n", chunkTrailer->magicNumber, chunkHeader->tag, tag); exit(1); }
@@ -203,7 +203,7 @@ void *debugMalloc(unsigned int length, int tag)
if (result == NULL) { - fprintf(stderr, "Cannot allocate %u bytes, tag = %d\n", length, tag); + fprintf(stderr, "Cannot allocate %u bytes, malloc tag = %d\n", length, tag); exit(1); }
@@ -218,14 +218,14 @@ void *debugRealloc(void *memory, unsigned int length, int tag)
if (result == NULL) { - fprintf(stderr, "Cannot re-allocate %u bytes, tag = %d\n", length, tag); + fprintf(stderr, "Cannot re-allocate %u bytes, malloc tag = %d\n", length, tag); exit(1); }
return result; }
-void debugFree(void *memory) +void debugFree(void *memory, int tag) { free(memory); } diff --git a/allocate.h b/allocate.h index 9777b3a..784a79e 100644 --- a/allocate.h +++ b/allocate.h @@ -2,4 +2,4 @@ void checkIntegrity(void); void checkLeak(void); void *debugMalloc(unsigned int length, int tag); void *debugRealloc(void *memory, unsigned int length, int tag); -void debugFree(void *memoryParameter); +void debugFree(void *memoryParameter, int tag); diff --git a/batman.c b/batman.c index 83e8468..8fa8ed8 100644 --- a/batman.c +++ b/batman.c @@ -215,7 +215,7 @@ void add_del_hna( struct orig_node *orig_node, int del ) {
if ( del ) {
- debugFree( orig_node->hna_buff ); + debugFree( orig_node->hna_buff, 101 ); orig_node->hna_buff_len = 0;
} @@ -483,8 +483,8 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla
if ( new_gwflags == 0 ) {
- list_del(gw_pos); - debugFree(gw_pos); + list_del( gw_pos ); + debugFree( gw_pos, 102 );
if (debug_level == 3) printf( "Gateway %s removed from gateway list\n", orig_str ); @@ -949,8 +949,8 @@ void send_outstanding_packets() {
list_del( forw_pos );
- debugFree( forw_node->pack_buff ); - debugFree( forw_node ); + debugFree( forw_node->pack_buff, 103 ); + debugFree( forw_node, 104 );
}
@@ -1047,8 +1047,8 @@ void purge() }
purged_packets++; - list_del(pack_pos); - debugFree(pack_node); + list_del( pack_pos ); + debugFree( pack_node, 105 );
} else {
@@ -1066,8 +1066,8 @@ void purge() addr_to_string(orig_node->orig, orig_str, sizeof (orig_str)); output("Removing orphaned neighbour %s for originator %s\n", neigh_str, orig_str); } - list_del(neigh_pos); - debugFree(neigh_node); + list_del( neigh_pos ); + debugFree( neigh_node, 106 ); } }
@@ -1089,8 +1089,8 @@ void purge() if (debug_level == 3) printf( "Removing gateway %s from gateway list\n", orig_str );
- list_del(gw_pos); - debugFree(gw_pos); + list_del( gw_pos ); + debugFree( gw_pos, 107 );
gw_purged = 1;
@@ -1106,7 +1106,7 @@ void purge() if ( orig_node->hna_buff_len > 0 ) {
add_del_hna( orig_node, 1 ); - debugFree( orig_node->hna_buff ); + debugFree( orig_node->hna_buff, 108 );
}
@@ -1119,8 +1119,8 @@ void purge()
}
- debugFree( orig_node->last_reply ); - debugFree( orig_node ); + debugFree( orig_node->last_reply, 109 ); + debugFree( orig_node, 110 );
} else if ( purged_packets > 0 ) {
@@ -1161,7 +1161,7 @@ void send_vis_packet() if(packet != NULL) { send_packet(packet, size * sizeof(unsigned char), &vis_if.addr, vis_if.sock); - debugFree(packet); + debugFree( packet, 111 ); } }
diff --git a/batman.h b/batman.h index 7250ad2..46a60ba 100644 --- a/batman.h +++ b/batman.h @@ -24,7 +24,7 @@ #include <pthread.h> #include "list.h"
-#define SOURCE_VERSION "0.1.1" +#define SOURCE_VERSION "0.1.1 beta" #define COMPAT_VERSION 2 #define PORT 1966 #define UNIDIRECTIONAL 0x80 @@ -35,7 +35,8 @@ * No configuration files or fancy command line switches yet * To experiment with B.A.T.M.A.N. settings change them here * and recompile the code - * Here is the stuff you may want to play with: */ + * Here is the stuff you may want to play with: + */
#define TTL 50 /* Time To Live of broadcast messages */ #define TIMEOUT 60000 /* sliding window size of received orginator messages in ms */ diff --git a/posix.c b/posix.c index 00f7118..a556f31 100644 --- a/posix.c +++ b/posix.c @@ -795,8 +795,8 @@ void *gw_listen( void *arg ) { FD_CLR(gw_client->sock, &wait_sockets); close( gw_client->sock );
- list_del(client_pos); - debugFree(client_pos); + list_del( client_pos ); + debugFree( client_pos, 201 );
}
@@ -840,8 +840,8 @@ void *gw_listen( void *arg ) { printf( "gateway: client %s timeout on interface %s\n", str2, batman_if->dev ); }
- list_del(client_pos); - debugFree(client_pos); + list_del( client_pos ); + debugFree( client_pos, 202 );
} else {
@@ -1047,7 +1047,7 @@ int main(int argc, char *argv[])
print_animation();
- printf( "\x1B[0;0H\t B.A.T.M.A.N.-III v%s (compability version %i)\n", SOURCE_VERSION, COMPAT_VERSION ); + printf( "\x1B[0;0HB.A.T.M.A.N.-III v%s (compability version %i)\n", SOURCE_VERSION, COMPAT_VERSION ); printf( "\x1B[9;0H \t May the bat guide your path ...\n\n\n" );
return (0);