<commit_before>/* 
 *  $Id: read.c,v 1.73 2013/03/28 21:04:29 rader Exp $
 */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <curses.h>
#include "cnagios.h"

/*------------------------------------------------------------------*/

int host_list_size = 0;
char *host_list[MAX_ITEMS][STATUS_LIST_ENTRY_SIZE];
struct obj_by_age *hosts_by_age;
int host_idx_to_level[MAX_ITEMS];
int service_list_size = 0;
char *service_list[MAX_ITEMS][STATUS_LIST_ENTRY_SIZE];
struct obj_by_age *services_by_age;
int service_idx_to_level[MAX_ITEMS];
int num_up, num_down;
int num_okay, num_warn, num_crit;
char last_update[21];
time_t last_update_int;

extern int object_mode;
extern int sort_mode;
extern int pad;
extern int color;

/*------------------------------------------------------------------*/

void
read_status()
{
  int i, j;
  struct obj_by_age *tmp, *prev, *new;

#if _DEBUG_
debug("read_status()...");
#endif


  /*--------------------------------------------------------*/
  /* free() up old status data... */

  while ( hosts_by_age != NULL ) {
    tmp = hosts_by_age;
    prev = hosts_by_age;
    while ( tmp->next != NULL ) {
     prev = tmp;
     tmp = tmp->next;
    }
    free(tmp);
    if ( prev == tmp ) {
      hosts_by_age = NULL;
    } else {
      prev->next = NULL;
    }
  }
  while ( services_by_age != NULL ) {
    tmp = services_by_age;
    prev = services_by_age;
    while ( tmp->next != NULL ) {
     prev = tmp;
     tmp = tmp->next;
    }
    free(tmp);
    if ( prev == tmp ) {
      services_by_age = NULL;
    } else {
      prev->next = NULL;
    }
  }
  for ( i = 0; i < host_list_size; i++ ) {
    for ( j = 0; j < STATUS_LIST_ENTRY_SIZE; j++ ) {
      if ( j == LAST_UPDATE ) { continue; }
      if ( j == LAST_STATE_CHANGE_INT ) { continue; }
      free(host_list[i][j]);
      host_list[i][j] = NULL;
    }
  }   
  for ( i = 0; i < service_list_size; i++ ) {
    for ( j = 0; j < STATUS_LIST_ENTRY_SIZE; j++ ) {
      if ( j == LAST_UPDATE ) { continue; } 
      if ( j == LAST_STATE_CHANGE_INT ) { continue; }
      free(service_list[i][j]);
      service_list[i][j] = NULL;
    }
  }

  /*--------------------------------------------------------*/
  /* parse status file... */
  switch(NAGIOS_VERSION) {
    case 1:
      read_v1_status();
    break;
    case 2:
    case 3:
      read_v23_status();
    break;
    default: 
      endwin();<commit_msg>Adding debug line to host and service entry free call to help hunt down memory corruption problems<commit_after>/* 
 *  $Id: read.c,v 1.73 2013/03/28 21:04:29 rader Exp $
 */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <curses.h>
#include "cnagios.h"

/*------------------------------------------------------------------*/

int host_list_size = 0;
char *host_list[MAX_ITEMS][STATUS_LIST_ENTRY_SIZE];
struct obj_by_age *hosts_by_age;
int host_idx_to_level[MAX_ITEMS];
int service_list_size = 0;
char *service_list[MAX_ITEMS][STATUS_LIST_ENTRY_SIZE];
struct obj_by_age *services_by_age;
int service_idx_to_level[MAX_ITEMS];
int num_up, num_down;
int num_okay, num_warn, num_crit;
char last_update[21];
time_t last_update_int;

extern int object_mode;
extern int sort_mode;
extern int pad;
extern int color;

/*------------------------------------------------------------------*/

void
read_status()
{
  int i, j;
  struct obj_by_age *tmp, *prev, *new;

#if _DEBUG_
debug("read_status()...");
#endif


  /*--------------------------------------------------------*/
  /* free() up old status data... */

  while ( hosts_by_age != NULL ) {
    tmp = hosts_by_age;
    prev = hosts_by_age;
    while ( tmp->next != NULL ) {
     prev = tmp;
     tmp = tmp->next;
    }
    free(tmp);
    if ( prev == tmp ) {
      hosts_by_age = NULL;
    } else {
      prev->next = NULL;
    }
  }
  while ( services_by_age != NULL ) {
    tmp = services_by_age;
    prev = services_by_age;
    while ( tmp->next != NULL ) {
     prev = tmp;
     tmp = tmp->next;
    }
    free(tmp);
    if ( prev == tmp ) {
      services_by_age = NULL;
    } else {
      prev->next = NULL;
    }
  }
  for ( i = 0; i < host_list_size; i++ ) {
    for ( j = 0; j < STATUS_LIST_ENTRY_SIZE; j++ ) {
      if ( j == LAST_UPDATE ) { continue; }
      if ( j == LAST_STATE_CHANGE_INT ) { continue; }
#if _DEBUG_
debug("freeing host: [%d,%d] %s", i, j, host_list[i][j]);
#endif
      free(host_list[i][j]);
      host_list[i][j] = NULL;
    }
  }   
  for ( i = 0; i < service_list_size; i++ ) {
    for ( j = 0; j < STATUS_LIST_ENTRY_SIZE; j++ ) {
      if ( j == LAST_UPDATE ) { continue; } 
      if ( j == LAST_STATE_CHANGE_INT ) { continue; }
#if _DEBUG_
debug("freeing service: [%d,%d] %s", i, j, service_list[i][j]);
#endif
      free(service_list[i][j]);
      service_list[i][j] = NULL;
    }
  }

  /*--------------------------------------------------------*/
  /* parse status file... */
  switch(NAGIOS_VERSION) {
    case 1:
      read_v1_status();
    break;
    case 2:
    case 3:
      read_v23_status();
    break;
    default: 
      endwin();
{'fraction_non_alphanumeric': 0.2334946757018393, 'fraction_numerical': 0.012003872216844144, 'mean_word_length': 1.977521613832853, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2504771', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1846, 'n_words': 423}