some memory usage cleanup based on valgrind report

This commit is contained in:
Brian Tierney 2009-11-16 20:10:48 +00:00
parent f4e1c1d4a4
commit dfb2d9d470
5 changed files with 11 additions and 12 deletions

View File

@ -481,16 +481,17 @@ char *
iperf_reporter_callback(struct iperf_test * test)
{
int total_packets = 0, lost_packets = 0, curr_state = 0;
char *message = NULL;
char *message_final = NULL;
char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN];
struct iperf_stream *sp = NULL;
iperf_size_t bytes = 0;
double start_time, end_time;
struct iperf_interval_results *ip = NULL;
char *message = (char *) malloc(MAX_RESULT_STRING);
char *message_final = (char *) malloc(MAX_RESULT_STRING);
memset(message_final, 0, strlen(message_final));
message = (char *)calloc(MAX_RESULT_STRING, sizeof(char));
message_final = (char *)calloc(MAX_RESULT_STRING, sizeof(char));
sp = test->streams;
curr_state = sp->settings->state;
@ -570,7 +571,7 @@ iperf_reporter_callback(struct iperf_test * test)
#if defined(linux) || defined(__FreeBSD__)
if (test->tcp_info)
{
printf("Final TCP_INFO results: \n");
//printf("Final TCP_INFO results: \n");
ip = sp->result->last_interval_results;
build_tcpinfo_message(ip, message);
safe_strcat(message_final, message);

View File

@ -56,7 +56,7 @@ int
param_received(struct iperf_stream * sp, struct param_exchange * param)
{
int result;
char *buf = (char *) malloc(sizeof(struct param_exchange));
char *buf = (char *) calloc(1, sizeof(struct param_exchange));
if (sp->settings->cookie[0] == '\0' ||
(strncmp(param->cookie, sp->settings->cookie, COOKIE_SIZE) == 0))

View File

@ -232,11 +232,11 @@ const char reportCSV_peer[] =
#if defined(linux)
const char report_tcpInfo[] =
"event=TCP_Info CWND=%u SND_SSTHRESH=%u RCV_SSTHRESH=%u UNACKED=%u SACK=%u LOST=%u RETRANS=%u FACK=%u RTT=%u REORDERING=%u";
"event=TCP_Info CWND=%u SND_SSTHRESH=%u RCV_SSTHRESH=%u UNACKED=%u SACK=%u LOST=%u RETRANS=%u FACK=%u RTT=%u REORDERING=%u\n";
#endif
#if defined(__FreeBSD__)
const char report_tcpInfo[] =
"event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u RTT=%u";
"event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u RTT=%u\n";
#endif

View File

@ -71,7 +71,6 @@ print_tcpinfo(struct iperf_interval_results *r)
void
build_tcpinfo_message(struct iperf_interval_results *r, char *message)
{
printf("in build_tcpinfo_message \n");
#if defined(linux)
sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_snd_ssthresh,
r->tcpInfo.tcpi_rcv_ssthresh, r->tcpInfo.tcpi_unacked, r->tcpInfo.tcpi_sacked,

View File

@ -65,7 +65,6 @@ update_timer(struct timer * tp, time_t sec, suseconds_t usec)
{
perror("gettimeofday");
}
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
@ -75,8 +74,8 @@ update_timer(struct timer * tp, time_t sec, suseconds_t usec)
struct timer *
new_timer(time_t sec, suseconds_t usec)
{
struct timer *tp;
tp = (struct timer *) malloc(sizeof(struct timer));
struct timer *tp = NULL;
tp = (struct timer *) calloc(1, sizeof(struct timer));
if (tp == NULL)
{
perror("malloc");
@ -88,7 +87,7 @@ new_timer(time_t sec, suseconds_t usec)
perror("gettimeofday");
return NULL;
}
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;