
#include<stdio.h>
#include<netinet/in.h>
#include<stdlib.h>
#include<pthread.h>

#include"sitar.h"
#include"sitar_scan.h"
#include<almemsys/almemsys.h>


extern global_data_t gd;



int malloc_set2(void)
{
int count;
count = 0;

#ifdef MALLOC_BUG
printf("MALLOC: malloc_set2():\n");
#endif

if((gd.td.fdstat=(int*)malloc(sizeof(int)*(gd.td.tcount + 2)))==NULL){exit(1);}
for(count = 0; count <= gd.td.tcount; count ++){
   gd.td.fdstat[count] = 0;
   }

// thread name
if((gd.td.mutex_name=(char **)malloc(sizeof(char *) * (gd.td.tcount + 2)))==NULL){exit(1);}
for(count = 0; count <= gd.td.tcount; count++){
   if((gd.td.mutex_name[count]=(char *)calloc(IP_LEN, sizeof(char)))==NULL){exit(1);}
   }

// mid name
if((gd.td.middle_name=(char **)malloc(sizeof(char *) * (gd.td.midcount + 2)))==NULL){exit(1);}
if((gd.td.middle_id=(char *)malloc(sizeof(char)*(gd.td.midcount + 2)))==NULL){exit(1);}
for(count = 0; count <= gd.td.midcount; count++){
   if((gd.td.middle_name[count]=(char *)calloc(IP_LEN, sizeof(char)))==NULL){exit(1);}
   gd.td.middle_id[count] = 0;
   }

return 0;
}





int malloc_set2_free(void)
{
int count;

#ifdef FREE_BUG
printf("FREE: malloc_set2_free():\n");
#endif

for(count = 0; count <= gd.td.tcount; count++){
   free(gd.td.mutex_name[count]);
   }

for(count = 0; count <= gd.td.midcount; count++){
   free(gd.td.middle_name[count]);
   }

free(gd.td.fdstat);
free(gd.td.mutex_name);
free(gd.td.middle_name);
free(gd.td.middle_id);
return 0;
}




