[netperf-dev] netperf4 commit notice r109 - branches/glib_migration/src

raj at netperf.org raj at netperf.org
Wed Mar 29 15:00:19 PST 2006


Author: raj
Date: 2006-03-29 15:00:17 -0800 (Wed, 29 Mar 2006)
New Revision: 109

Modified:
   branches/glib_migration/src/netlib.c
   branches/glib_migration/src/netmsg.c
   branches/glib_migration/src/netperf.h
   branches/glib_migration/src/netserver.c
   branches/glib_migration/src/netsysstats_common.c
   branches/glib_migration/src/netsysstats_linux.c
   branches/glib_migration/src/nettest_bsd.c
Log:
Some valgrind cleanups - fix bogus references, plug a few memory leaks
on the netserver side of things.  There are still some leaks - many 
related to not free'ing stuff returned by libxml calls.  The netperf
side of things is not yet checked.


Modified: branches/glib_migration/src/netlib.c
===================================================================
--- branches/glib_migration/src/netlib.c	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/netlib.c	2006-03-29 23:00:17 UTC (rev 109)
@@ -1378,16 +1378,20 @@
   int      fnlen = 0;
   int      rc = NPE_FUNC_NAME_TOO_LONG;
   char     func_name[NETPERF_MAX_TEST_FUNCTION_NAME];
+  xmlChar *la_file;
+  char     lib_file[NETPERF_MAX_TEST_LIBRARY_NAME];
 
 
   if (debug) {
-    fprintf(where,"get_test_func enter test %p func %s\n",test, func);
+    g_fprintf(where,
+	      "%s enter test %p func %s\n",
+	      __func__,
+	      test,
+	      func);
     fflush(where);
   }
 
   if (lib_handle == NULL) {
-    xmlChar *la_file;
-    char lib_file[NETPERF_MAX_TEST_LIBRARY_NAME];
     /* load the library for the test */
     la_file   = xmlGetProp(test->node,(const xmlChar *)"library");
     map_la_to_lib(la_file,lib_file);
@@ -2304,6 +2308,10 @@
 		fprintf(where,"failed\n");
 	      }
             }
+	    g_free(chars_to_send);
+	    /* this may not be the 100% correct place for this */
+	    xmlFreeDoc(doc);
+	    free(control_message);
           } else {
             rc = NPE_SEND_CTL_MSG_XMLDOCDUMPMEMORY_FAILED;
           }
@@ -2427,7 +2435,10 @@
 		  message_state->bytes_remaining);
       }
       g_free(message_state->buffer);
-      message_state->buffer = g_malloc(message_state->bytes_remaining);
+      /* allocate an extra byte to make sure we can null-terminate the
+	 buffer on the off chance we do something like try to print it
+	 as a string... raj 2006-03-29 */
+      message_state->buffer = g_malloc(message_state->bytes_remaining+1);
     }
   }
 
@@ -2464,6 +2475,9 @@
 
     if (0 == message_state->bytes_remaining) {
       /* we have an entire message, time to process it */
+      /* make sure we are NULL terminated just in case someone tries
+	 to print it as a string or something. */
+      message_state->buffer[message_state->bytes_received] = '\0';
       ret = xml_parse_control_message(message_state->buffer,
 				      message_state->bytes_received,
 				      data,

Modified: branches/glib_migration/src/netmsg.c
===================================================================
--- branches/glib_migration/src/netmsg.c	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/netmsg.c	2006-03-29 23:00:17 UTC (rev 109)
@@ -212,6 +212,7 @@
     }
   }
   xmlFreeDoc(doc);
+  if (fromnid) free(fromnid);
 
   NETPERF_DEBUG_EXIT(debug,where);
 
@@ -289,7 +290,10 @@
       }
       rc = NPE_SEND_VERSION_XMLSETPROP_FAILED;
     }
-  } else {
+    /* now that we are done with it, best to free the message node */
+    xmlFreeNode(message);
+  }
+  else {
     if (debug) {
       fprintf(where,
               "send_version_message: xmlNewNode failed\n");

Modified: branches/glib_migration/src/netperf.h
===================================================================
--- branches/glib_migration/src/netperf.h	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/netperf.h	2006-03-29 23:00:17 UTC (rev 109)
@@ -106,6 +106,8 @@
 #error Netperf4 requires either glib or pthreads
 #endif
 
+#define NETPERF_RING_BUFFER_STRING "netperf4 ring data"
+
 #include "netperf_hist.h"
 
 #ifdef WIN32

Modified: branches/glib_migration/src/netserver.c
===================================================================
--- branches/glib_migration/src/netserver.c	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/netserver.c	2006-03-29 23:00:17 UTC (rev 109)
@@ -658,7 +658,8 @@
               fflush(where);
             }
           }
-        }
+	  xmlFreeNode(msg);
+	}
       }
       test = test->next;
       if (new == TEST_DEAD) {

Modified: branches/glib_migration/src/netsysstats_common.c
===================================================================
--- branches/glib_migration/src/netsysstats_common.c	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/netsysstats_common.c	2006-03-29 23:00:17 UTC (rev 109)
@@ -296,6 +296,11 @@
   return(ap);
 }
 
+/* NOTE - we need to figure-out where/when to free the attributes
+   returned by set_*_attribute otherwise we have a memory leak. what I
+   don't know is if the attribute pointers can/should be freed here or
+   if they become part of the xmlNode... */
+
 static xmlAttrPtr
 add_per_cpu_attributes(test_t *test,
 		       xmlNodePtr stats,
@@ -502,10 +507,19 @@
 	       good. raj 2005-10-27
 	       for good measure, make sure we are doing a memset for
 	       the proper size of each of these blessed things! raj
-	       2006-01-23 */ 
+	       2006-01-23
+	       and do it for all the counters just to make sure that
+	       stuff like valgrind remains happy. raj 2006-02-29 */
+
 	    memset(tsd->total_sys_counters,0,sizeof(cpu_time_counters_t));
 	    memset(tsd->total_cpu_counters,0,
 		   (num_cpus * sizeof(cpu_time_counters_t)));
+	    memset(tsd->starting_cpu_counters,0,
+		   (num_cpus * sizeof(cpu_time_counters_t)));
+	    memset(tsd->ending_cpu_counters,0,
+		   (num_cpus * sizeof(cpu_time_counters_t)));
+	    memset(tsd->delta_cpu_counters,0,
+		   (num_cpus * sizeof(cpu_time_counters_t)));
 	    SET_TEST_STATE(TEST_INIT);
 	  } else {
 	    /* lets see about cleaning-up some memory shall we? */

Modified: branches/glib_migration/src/netsysstats_linux.c
===================================================================
--- branches/glib_migration/src/netsysstats_linux.c	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/netsysstats_linux.c	2006-03-29 23:00:17 UTC (rev 109)
@@ -121,7 +121,11 @@
 
   if (!proc_stat_buf) {
     proc_stat_buflen = N_CPU_LINES (tsd->num_cpus) * CPU_LINE_LENGTH;
-    proc_stat_buf = (char *)malloc (proc_stat_buflen);
+    /* we allocate an extra byte to allow it to be null terminated in
+       the event we do something silly like an fprintf of the
+       proc_stat_buf as a string... :) raj 2006-03-29 */
+    proc_stat_buf = (char *)malloc (proc_stat_buflen+1);
+    proc_stat_buf[proc_stat_buflen] = '\0';
     if (!proc_stat_buf) {
       fprintf (stderr, "Cannot allocate buffer memory!\n");
       close(proc_stat_fd);

Modified: branches/glib_migration/src/nettest_bsd.c
===================================================================
--- branches/glib_migration/src/nettest_bsd.c	2006-03-28 23:44:53 UTC (rev 108)
+++ branches/glib_migration/src/nettest_bsd.c	2006-03-29 23:00:17 UTC (rev 109)
@@ -420,6 +420,9 @@
                         BSDE_GETADDRINFO_ERROR,
                         gai_strerror(error));
   }
+  if (string) free(string);
+  if (remotehost) free(remotehost);
+  if (remoteport) free(remoteport);
 }
 
 
@@ -550,7 +553,7 @@
     if (i == 1) {
       first_link = temp_link;
     }
-    temp_link->buffer_base = (char *)malloc(malloc_size);
+    temp_link->buffer_base = (char *)g_malloc(malloc_size);
     temp_link->buffer_ptr = (char *)(( (long)(temp_link->buffer_base) +
                           (long)alignment - 1) &
                          ~((long)alignment - 1));
@@ -569,6 +572,12 @@
         bytes_left -= bytes_read;
       }
     }
+    else {
+      /* put our own special "stamp" upon the buffer */
+      strncpy(temp_link->buffer_ptr,
+	      NETPERF_RING_BUFFER_STRING,
+	      buffer_size);
+    }
     temp_link->next = prev_link;
     prev_link = temp_link;
   }
@@ -1089,8 +1098,11 @@
     }
   }
   if (test->debug) {
-    fprintf(test->where,"bsd_test_get_stats: exiting for %s test %s\n",
-            test->id, test->test_name);
+    fprintf(test->where,
+	    "%s: exiting for %s test %s\n",
+	    __func__,
+            test->id,
+	    test->test_name);
     fflush(test->where);
   }
   return(stats);



More information about the netperf-dev mailing list