00001 /* ----------------------------------------------------------------------------- 00002 * dallocate.c 00003 * 00004 * iPDC - Phasor Data Concentrator 00005 * 00006 * Copyright (C) 2011 Nitesh Pandit 00007 * Copyright (C) 2011 Kedar V. Khandeparkar 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * as published by the Free Software Foundation; either version 2 00012 * of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 * 00023 * Authors: 00024 * Kedar V. Khandeparkar <kedar.khandeparkar@gmail.com> 00025 * Nitesh Pandit <panditnitesh@gmail.com> 00026 * 00027 * ----------------------------------------------------------------------------- */ 00028 00029 00030 #include <stdio.h> 00031 #include <string.h> 00032 #include <stdlib.h> 00033 #include "parser.h" 00034 #include "dallocate.h" 00035 #include "global.h" 00036 00037 /* ------------------------------------------------------------------------------------ */ 00038 /* Functions defined in dallocate.c */ 00039 /* ------------------------------------------------------------------------------------ */ 00040 00041 /* 1. void free_cfgframe_object(struct cfg_frame *cfg) */ 00042 /* 2. void free_2darray(char** array, int x) */ 00043 00044 /* ------------------------------------------------------------------------------------ */ 00045 00046 00047 /* -------------------------------------------------------------*/ 00048 /* FUNCTION free_cfgframe_object(): */ 00049 /* It frees memory allocated to cfg objects. */ 00050 /* ------------------------------------------------------------ */ 00051 00052 void free_cfgframe_object(struct cfg_frame *cfg) { 00053 00054 int j = 0; 00055 struct dgnames *t_dgnames,*r_dgnames; 00056 printf("Inside free_cfgframe_object()\n"); 00057 00058 while(j<cfg->num_pmu) { 00059 00060 if(cfg->pmu[j]->phnmr != 0) 00061 free_2darray(cfg->pmu[j]->cnext->phnames,cfg->pmu[j]->phnmr); 00062 if(cfg->pmu[j]->annmr != 0) 00063 free_2darray(cfg->pmu[j]->cnext->angnames,cfg->pmu[j]->annmr); 00064 00065 if(cfg->pmu[j]->dgnmr != 0) { 00066 00067 t_dgnames = cfg->pmu[j]->cnext->first; 00068 while(t_dgnames != NULL) { 00069 00070 r_dgnames = t_dgnames->dg_next; 00071 free_2darray(t_dgnames->dgn,16); 00072 t_dgnames = r_dgnames; 00073 00074 } 00075 } 00076 00077 // free_2darray_l(cfg->pmu[j]->phunit,cfg->pmu[j]->phnmr); 00078 // free_2darray_l(cfg->pmu[j]->anunit,cfg->pmu[j]->annmr); 00079 if(cfg->pmu[j]->dgnmr != 0) 00080 free_2darray(cfg->pmu[j]->dgunit,cfg->pmu[j]->dgnmr); 00081 00082 00083 j++; 00084 } // End of While 00085 00086 free(cfg); 00087 00088 } 00089 00090 /* -------------------------------------------------------------*/ 00091 /* FUNCTION free_2darray: */ 00092 /* It frees memory allocated to 2D Arrays. */ 00093 /* -------------------------------------------------------------*/ 00094 00095 void free_2darray_l(long int **array, int x){ 00096 00097 int i; 00098 for(i=0; i<x; i++) 00099 free(array[i]); 00100 free(array); 00101 } 00102 00103 /* -------------------------------------------------------------*/ 00104 /* FUNCTION free_2darray: */ 00105 /* It frees memory allocated to 2D Arrays. */ 00106 /* -------------------------------------------------------------*/ 00107 00108 void free_2darray(unsigned char **array, int x){ 00109 00110 int i; 00111 for(i=0; i<x; i++) 00112 free(array[i]); 00113 free(array); 00114 }
1.6.3