Michael Schwendt 40f163
Hi,
Michael Schwendt 40f163
Michael Schwendt 40f163
This patch removes a couple unnecessary memsets, fixes some memory leaks
Michael Schwendt 40f163
associated with strlastslash usage, fixes some memory leaks in populate_tree,
Michael Schwendt 40f163
and moves a couple assignments closer to where they are used in case they are
Michael Schwendt 40f163
not needed.
Michael Schwendt 40f163
Michael Schwendt 40f163
-Steve
Michael Schwendt 40f163
Michael Schwendt 40f163
Michael Schwendt 40f163
diff -ur aide-0.12_rc1.orig/src/base64.c aide-0.12_rc1/src/base64.c
Michael Schwendt 40f163
--- aide-0.12_rc1.orig/src/base64.c	2006-10-16 13:31:43.000000000 -0400
Michael Schwendt 40f163
+++ aide-0.12_rc1/src/base64.c	2006-10-16 13:43:08.000000000 -0400
Michael Schwendt 40f163
@@ -103,8 +103,6 @@
Michael Schwendt 40f163
   }
Michael Schwendt 40f163
   outbuf = (char *)malloc(sizeof(char)*B64_BUF);
Michael Schwendt 40f163
   
Michael Schwendt 40f163
-  memset((void*)outbuf,0,B64_BUF);
Michael Schwendt 40f163
-  
Michael Schwendt 40f163
   /* Initialize working pointers */
Michael Schwendt 40f163
   inb = src;
Michael Schwendt 40f163
   i = 0;
Michael Schwendt 40f163
@@ -191,11 +189,9 @@
Michael Schwendt 40f163
     return NULL;
Michael Schwendt 40f163
 
Michael Schwendt 40f163
 
Michael Schwendt 40f163
-
Michael Schwendt 40f163
   /* Initialize working pointers */
Michael Schwendt 40f163
   inb = src;
Michael Schwendt 40f163
   outbuf = (byte *)malloc(sizeof(byte)*B64_BUF);
Michael Schwendt 40f163
-  memset(outbuf,0,sizeof(byte)*B64_BUF);
Michael Schwendt 40f163
 
Michael Schwendt 40f163
   l = 0;
Michael Schwendt 40f163
   triple = 0;
Michael Schwendt 40f163
diff -ur aide-0.12_rc1.orig/src/commandconf.c aide-0.12_rc1/src/commandconf.c
Michael Schwendt 40f163
--- aide-0.12_rc1.orig/src/commandconf.c	2006-10-16 13:31:43.000000000 -0400
Michael Schwendt 40f163
+++ aide-0.12_rc1/src/commandconf.c	2006-10-16 13:43:08.000000000 -0400
Michael Schwendt 40f163
@@ -240,11 +240,11 @@
Michael Schwendt 40f163
 {
Michael Schwendt 40f163
   int retval=0;
Michael Schwendt 40f163
   int c=0;
Michael Schwendt 40f163
-  char* tmp=NULL;
Michael Schwendt 40f163
   int err=0;
Michael Schwendt 40f163
-  int* domd=0;
Michael Schwendt 40f163
+  int* domd=NULL;
Michael Schwendt 40f163
   url_t* db_url=NULL;
Michael Schwendt 40f163
 #ifdef WITH_MHASH
Michael Schwendt 40f163
+  char* tmp=NULL;
Michael Schwendt 40f163
   MHASH* md=NULL;
Michael Schwendt 40f163
   void* key=NULL;
Michael Schwendt 40f163
   int keylen;
Michael Schwendt 40f163
@@ -401,7 +401,7 @@
Michael Schwendt 40f163
 
Michael Schwendt 40f163
 int check_db_order(DB_FIELD* d,int size, DB_FIELD a)
Michael Schwendt 40f163
 {
Michael Schwendt 40f163
-  int i=0;
Michael Schwendt 40f163
+  int i;
Michael Schwendt 40f163
   for(i=0;i
Michael Schwendt 40f163
     if(d[i]==a)
Michael Schwendt 40f163
       return RETFAIL;
Michael Schwendt 40f163
diff -ur aide-0.12_rc1.orig/src/gen_list.c aide-0.12_rc1/src/gen_list.c
Michael Schwendt 40f163
--- aide-0.12_rc1.orig/src/gen_list.c	2006-10-16 13:31:43.000000000 -0400
Michael Schwendt 40f163
+++ aide-0.12_rc1/src/gen_list.c	2006-10-16 14:09:49.000000000 -0400
Michael Schwendt 40f163
@@ -229,8 +229,7 @@
Michael Schwendt 40f163
 {
Michael Schwendt 40f163
     if( r!=NULL ){
Michael Schwendt 40f163
         node->conf_lineno = r->conf_lineno;  
Michael Schwendt 40f163
-        node->rx=(char*)malloc(strlen(r->rx)+1);
Michael Schwendt 40f163
-        strcpy(node->rx,r->rx);
Michael Schwendt 40f163
+        node->rx=strdup(r->rx);
Michael Schwendt 40f163
     } else {
Michael Schwendt 40f163
         node->conf_lineno = -1;
Michael Schwendt 40f163
         node->rx=NULL;
Michael Schwendt 40f163
@@ -265,13 +264,17 @@
Michael Schwendt 40f163
     if(isrx){
Michael Schwendt 40f163
       parent=get_seltree_node(tree,tmprxtok);
Michael Schwendt 40f163
     }else {
Michael Schwendt 40f163
-      parent=get_seltree_node(tree,strlastslash(path));
Michael Schwendt 40f163
+      char* dirn=strlastslash(path);
Michael Schwendt 40f163
+      parent=get_seltree_node(tree,dirn);
Michael Schwendt 40f163
+      free(dirn);
Michael Schwendt 40f163
     }      
Michael Schwendt 40f163
     if(parent==NULL){
Michael Schwendt 40f163
       if(isrx){
Michael Schwendt 40f163
 	parent=new_seltree_node(tree,tmprxtok,isrx,r);
Michael Schwendt 40f163
       }else {
Michael Schwendt 40f163
-	parent=new_seltree_node(tree,strlastslash(path),isrx,r);
Michael Schwendt 40f163
+        char* dirn=strlastslash(path);
Michael Schwendt 40f163
+        parent=new_seltree_node(tree,dirn,isrx,r);
Michael Schwendt 40f163
+        free(dirn);
Michael Schwendt 40f163
       }
Michael Schwendt 40f163
     }
Michael Schwendt 40f163
     free(tmprxtok);
Michael Schwendt 40f163
@@ -306,8 +309,7 @@
Michael Schwendt 40f163
     error(240,"Handling %s with %c \"%s\" with node \"%s\"\n",rxtok,type,curr_rule->rx,curnode->path);
Michael Schwendt 40f163
 	
Michael Schwendt 40f163
     
Michael Schwendt 40f163
-    /* We have to add '^' to the first charaster of string... 
Michael Schwendt 40f163
-     *
Michael Schwendt 40f163
+    /* We have to add '^' to the first character of string... 
Michael Schwendt 40f163
      */
Michael Schwendt 40f163
 
Michael Schwendt 40f163
     data=(char*)malloc(strlen(curr_rule->rx)+1+1);
Michael Schwendt 40f163
@@ -1518,9 +1520,14 @@
Michael Schwendt 40f163
 	if((add=check_rxtree(old->filename,tree,&attr))>0){
Michael Schwendt 40f163
 	  add_file_to_tree(tree,old,DB_OLD,0,attr);
Michael Schwendt 40f163
 	  i++;
Michael Schwendt 40f163
-	}else if(!initdbwarningprinted){
Michael Schwendt 40f163
-	  error(3,_("WARNING: Old db contains a file that shouldn\'t be there, run --init or --update\n"));
Michael Schwendt 40f163
-	  initdbwarningprinted=1;
Michael Schwendt 40f163
+	}else{
Michael Schwendt 40f163
+          free_db_line(old);
Michael Schwendt 40f163
+          free(old);
Michael Schwendt 40f163
+          old=NULL;
Michael Schwendt 40f163
+          if(!initdbwarningprinted){
Michael Schwendt 40f163
+	    error(3,_("WARNING: Old db contains a file that shouldn\'t be there, run --init or --update\n"));
Michael Schwendt 40f163
+	    initdbwarningprinted=1;
Michael Schwendt 40f163
+	  }
Michael Schwendt 40f163
 	}
Michael Schwendt 40f163
 	if(i<100){
Michael Schwendt 40f163
 	  old=db_readline(DB_OLD);
Michael Schwendt 40f163
@@ -1543,6 +1550,10 @@
Michael Schwendt 40f163
 	if((add=check_rxtree(new->filename,tree,&attr))>0){
Michael Schwendt 40f163
 	  add_file_to_tree(tree,new,DB_NEW,0,attr);
Michael Schwendt 40f163
 	  i++;
Michael Schwendt 40f163
+	} else {
Michael Schwendt 40f163
+          free_db_line(new);
Michael Schwendt 40f163
+          free(new);
Michael Schwendt 40f163
+          new=NULL;
Michael Schwendt 40f163
 	}
Michael Schwendt 40f163
 	if(i<100){
Michael Schwendt 40f163
 	  new=db_readline(DB_NEW);
Michael Schwendt 40f163
@@ -1568,6 +1579,8 @@
Michael Schwendt 40f163
 	}
Michael Schwendt 40f163
 	if((conf->action&DO_INIT)&&!(conf->action&DO_COMPARE)){
Michael Schwendt 40f163
 	  free_db_line(new);
Michael Schwendt 40f163
+          free(new);
Michael Schwendt 40f163
+          new=NULL;
Michael Schwendt 40f163
 	}
Michael Schwendt 40f163
 	if(i<100){
Michael Schwendt 40f163
 	  new=db_readline(DB_DISK);
Michael Schwendt 40f163
diff -ur aide-0.12_rc1.orig/src/symboltable.c aide-0.12_rc1/src/symboltable.c
Michael Schwendt 40f163
--- aide-0.12_rc1.orig/src/symboltable.c	2006-10-16 13:31:43.000000000 -0400
Michael Schwendt 40f163
+++ aide-0.12_rc1/src/symboltable.c	2006-10-16 13:43:08.000000000 -0400
Michael Schwendt 40f163
@@ -34,13 +34,13 @@
Michael Schwendt 40f163
     return NULL;
Michael Schwendt 40f163
   }
Michael Schwendt 40f163
 
Michael Schwendt 40f163
-  l=item->prev;
Michael Schwendt 40f163
   p=item;
Michael Schwendt 40f163
   while(p!=NULL){
Michael Schwendt 40f163
     if (strcmp(s,((symba*)p->data)->name)==0) return p;
Michael Schwendt 40f163
     p=p->next;
Michael Schwendt 40f163
   }
Michael Schwendt 40f163
     
Michael Schwendt 40f163
+  l=item->prev;
Michael Schwendt 40f163
   while(l!=NULL){
Michael Schwendt 40f163
     /* Insert bug to here return l-> return p */
Michael Schwendt 40f163
     if (strcmp(s,((symba*)l->data)->name)==0) return l; 
Michael Schwendt 40f163