/*
  File:  proxy_deinit.c 
  
  Description:  deinitialization functions for proxy structures.
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "config.h"
#include "proxy_protos.h"

/* 
   free allocated memory, close open sockets, etc 
*/

void
deinit_mdata ( struct mdata *md )
{
  int i;

  if ( md ) {

    if ( md->r ) {

      /* don't touch fd 0,1,2 (stdin,stdout,stderr) */

      for ( i = 3; i < md->nofile; i++ ) {

	if ( md->r[i].status == FD_OPEN ) {
	  close ( i );
	}

	if ( md->r[i].queue ) g_slist_free(md->r[i].queue);

      }
    }

    free( md->r );

    if ( md->m ) g_mem_chunk_destroy ( md->m );

    if ( md->server_sock ) close ( md->server_sock );
    log_msg(md,"===> %s version %s finished",PACKAGE,VERSION);
    if ( md->log_fp != stderr ) fclose ( md->log_fp );
  }
  free ( md );
}


/* callback to "free" an unused memory chunk atom */

void 
chunk_free ( void *data, void *user_data )
{
  g_mem_chunk_free ( (GMemChunk *)user_data, data );
}



syntax highlighted by Code2HTML, v. 0.9.1