Commit b8e74174 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Used NMXP_MEM_MALLOC NMXP_MEM_FREE and NMXP_MEM_STRDUP


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@974 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 831afbf4
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.h,v 1.49 2008-03-20 12:42:08 mtheo Exp $
* $Id: nmxp.h,v 1.50 2008-03-28 13:21:24 mtheo Exp $
*
*/
......@@ -988,6 +988,7 @@ Mail bug reports and suggestions to <quintiliani@ingv.it>.
#include "nmxp_base.h"
#include "nmxp_crc32.h"
#include "nmxp_memory.h"
#define NMXP_MAX_MSCHAN_MSEC 15000
......
......@@ -7,11 +7,12 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.c,v 1.80 2008-03-28 07:32:31 mtheo Exp $
* $Id: nmxp.c,v 1.81 2008-03-28 13:21:24 mtheo Exp $
*
*/
#include "nmxp.h"
#include "nmxp_memory.h"
#include "config.h"
......@@ -79,7 +80,7 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList, int32_t shortTermCompletion, int32_t out_format, NMXP_BUFFER_FLAG buffer_flag) {
int ret;
int32_t buffer_length = 16 + (4 * channelList->number);
char *buffer = malloc(buffer_length);
char *buffer = NMXP_MEM_MALLOC(buffer_length);
int32_t app, i, disp;
disp=0;
......@@ -109,7 +110,7 @@ int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList
ret = nmxp_sendMessage(isock, NMXP_MSG_ADDTIMESERIESCHANNELS, buffer, buffer_length);
if(buffer) {
free(buffer);
NMXP_MEM_FREE(buffer);
buffer = NULL;
}
return ret;
......@@ -372,7 +373,7 @@ int nmxp_waitReady(int isock) {
if(length > 0) {
if(type == NMXP_MSG_TERMINATESUBSCRIPTION) {
char *str_msg = NULL;
char *buf_app = (char *) malloc(sizeof(char) * length);
char *buf_app = (char *) NMXP_MEM_MALLOC(sizeof(char) * length);
int32_t reason;
memcpy(&reason, buf_app, sizeof(reason));
reason = ntohl(reason);
......@@ -383,7 +384,7 @@ int nmxp_waitReady(int isock) {
(reason == 0)? "Normal" : (reason == 1)? "Error" : (reason == 2)? "Timeout" : "Unknown",
str_msg);
if(buf_app) {
free(buf_app);
NMXP_MEM_FREE(buf_app);
buf_app = NULL;
}
/* Close the socket*/
......@@ -396,10 +397,10 @@ int nmxp_waitReady(int isock) {
app = ntohl(app);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "value = %d\n", app);
} else {
char *buf_app = (char *) malloc(sizeof(char) * length);
char *buf_app = (char *) NMXP_MEM_MALLOC(sizeof(char) * length);
rc = nmxp_recv_ctrl(isock, buf_app, length, 0, &recv_errno);
if(buf_app) {
free(buf_app);
NMXP_MEM_FREE(buf_app);
buf_app = NULL;
}
}
......@@ -495,7 +496,7 @@ NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_
}
if(channelList) {
free(channelList);
NMXP_MEM_FREE(channelList);
channelList = NULL;
}
......@@ -696,7 +697,7 @@ void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_t
raw_stream_buffer->max_pdlist_items = max_tolerable_latency * 4;
raw_stream_buffer->timeoutrecv = timeoutrecv;
raw_stream_buffer->n_pdlist = 0;
raw_stream_buffer->pdlist = (NMXP_DATA_PROCESS **) malloc (raw_stream_buffer->max_pdlist_items * sizeof(NMXP_DATA_PROCESS *));
raw_stream_buffer->pdlist = (NMXP_DATA_PROCESS **) NMXP_MEM_MALLOC(raw_stream_buffer->max_pdlist_items * sizeof(NMXP_DATA_PROCESS *));
for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
raw_stream_buffer->pdlist[j] = NULL;
}
......@@ -711,18 +712,18 @@ void nmxp_raw_stream_free(NMXP_RAW_STREAM_DATA *raw_stream_buffer) {
for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
if(raw_stream_buffer->pdlist[j]) {
if(raw_stream_buffer->pdlist[j]->buffer) {
free(raw_stream_buffer->pdlist[j]->buffer);
NMXP_MEM_FREE(raw_stream_buffer->pdlist[j]->buffer);
raw_stream_buffer->pdlist[j]->buffer = NULL;
}
if(raw_stream_buffer->pdlist[j]->pDataPtr) {
free(raw_stream_buffer->pdlist[j]->pDataPtr);
NMXP_MEM_FREE(raw_stream_buffer->pdlist[j]->pDataPtr);
raw_stream_buffer->pdlist[j]->pDataPtr = NULL;
}
free(raw_stream_buffer->pdlist[j]);
NMXP_MEM_FREE(raw_stream_buffer->pdlist[j]);
raw_stream_buffer->pdlist[j] = NULL;
}
}
free(raw_stream_buffer->pdlist);
NMXP_MEM_FREE(raw_stream_buffer->pdlist);
raw_stream_buffer->pdlist = NULL;
}
}
......@@ -752,16 +753,16 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
*/
/* Allocate memory for pd and copy a_pd */
pd = (NMXP_DATA_PROCESS *) malloc (sizeof(NMXP_DATA_PROCESS));
pd = (NMXP_DATA_PROCESS *) NMXP_MEM_MALLOC(sizeof(NMXP_DATA_PROCESS));
memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS));
if(a_pd->length > 0) {
pd->buffer = malloc(pd->length);
pd->buffer = NMXP_MEM_MALLOC(pd->length);
memcpy(pd->buffer, a_pd->buffer, a_pd->length);
} else {
pd->buffer = NULL;
}
if(a_pd->nSamp * sizeof(int) > 0) {
pd->pDataPtr = (int *) malloc(a_pd->nSamp * sizeof(int));
pd->pDataPtr = (int *) NMXP_MEM_MALLOC(a_pd->nSamp * sizeof(int));
memcpy(pd->pDataPtr, a_pd->pDataPtr, a_pd->nSamp * sizeof(int));
} else {
pd->pDataPtr = NULL;
......@@ -830,15 +831,15 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
/* Free handled packet */
if(p->pdlist[0]->buffer) {
free(p->pdlist[0]->buffer);
NMXP_MEM_FREE(p->pdlist[0]->buffer);
p->pdlist[0]->buffer = NULL;
}
if(p->pdlist[0]->pDataPtr) {
free(p->pdlist[0]->pDataPtr);
NMXP_MEM_FREE(p->pdlist[0]->pDataPtr);
p->pdlist[0]->pDataPtr = NULL;
}
if(p->pdlist[0]) {
free(p->pdlist[0]);
NMXP_MEM_FREE(p->pdlist[0]);
p->pdlist[0] = NULL;
}
if(pd) {
......@@ -976,15 +977,15 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
for(k=0; k < p->n_pdlist; k++) {
if(k < j) {
if(p->pdlist[k]->buffer) {
free(p->pdlist[k]->buffer);
NMXP_MEM_FREE(p->pdlist[k]->buffer);
p->pdlist[k]->buffer = NULL;
}
if(p->pdlist[k]->pDataPtr) {
free(p->pdlist[k]->pDataPtr);
NMXP_MEM_FREE(p->pdlist[k]->pDataPtr);
p->pdlist[k]->pDataPtr = NULL;
}
if(p->pdlist[k]) {
free(p->pdlist[k]);
NMXP_MEM_FREE(p->pdlist[k]);
p->pdlist[k] = NULL;
}
}
......
......@@ -7,12 +7,13 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.c,v 1.66 2008-03-26 15:48:38 mtheo Exp $
* $Id: nmxp_base.c,v 1.67 2008-03-28 13:21:24 mtheo Exp $
*
*/
#include "config.h"
#include "nmxp_base.h"
#include "nmxp_memory.h"
#ifdef HAVE_WINDOWS_H
#include "nmxp_win.h"
#endif
......@@ -402,7 +403,7 @@ int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t
if( ret == NMXP_SOCKET_OK ) {
if (*length > 0) {
*buffer = malloc(*length);
*buffer = NMXP_MEM_MALLOC(*length);
ret = nmxp_recv_ctrl(isock, *buffer, *length, 0, recv_errno);
if(*type == NMXP_MSG_TERMINATESUBSCRIPTION) {
......
......@@ -7,12 +7,13 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_chan.c,v 1.39 2008-03-28 07:32:31 mtheo Exp $
* $Id: nmxp_chan.c,v 1.40 2008-03-28 13:21:24 mtheo Exp $
*
*/
#include "nmxp_chan.h"
#include "nmxp_base.h"
#include "nmxp_memory.h"
#include <string.h>
#include <stdlib.h>
......@@ -30,7 +31,7 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio
channel_code[0] = 0;
network_code[0] = 0;
tmp_name = strdup(net_dot_station_dot_channel);
tmp_name = NMXP_MEM_STRDUP(net_dot_station_dot_channel);
/* count '.' */
i=0;
while(i < strlen(tmp_name) && !errors) {
......@@ -66,7 +67,7 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio
}
if(tmp_name) {
free(tmp_name);
NMXP_MEM_FREE(tmp_name);
tmp_name = NULL;
}
......@@ -256,7 +257,7 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat
int chan_number = channelList->number;
int i_chan = 0;
ret_channelList = (NMXP_CHAN_LIST *) malloc(sizeof(NMXP_CHAN_LIST));
ret_channelList = (NMXP_CHAN_LIST *) NMXP_MEM_MALLOC(sizeof(NMXP_CHAN_LIST));
ret_channelList->number = 0;
for (i_chan = 0; i_chan < chan_number; i_chan++)
......@@ -285,7 +286,7 @@ NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE
char *nmxp_channel_name = NULL;
char nmxp_channel_name_duplicated[50];
ret_channelList = (NMXP_CHAN_LIST_NET *) malloc(sizeof(NMXP_CHAN_LIST_NET));
ret_channelList = (NMXP_CHAN_LIST_NET *) NMXP_MEM_MALLOC(sizeof(NMXP_CHAN_LIST_NET));
ret_channelList->number = 0;
istalist = 0;
......@@ -437,7 +438,7 @@ void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list) {
if(iter) {
iter_next = iter->next;
while(iter) {
free(iter);
NMXP_MEM_FREE(iter);
iter = iter_next;
iter_next = iter->next;
}
......@@ -490,7 +491,7 @@ NMXP_META_CHAN_LIST *nmxp_meta_chan_add(NMXP_META_CHAN_LIST **chan_list, int32_t
sorttype = NMXP_META_SORT_KEY;
}
new_item = (NMXP_META_CHAN_LIST *) malloc(sizeof(NMXP_META_CHAN_LIST));
new_item = (NMXP_META_CHAN_LIST *) NMXP_MEM_MALLOC(sizeof(NMXP_META_CHAN_LIST));
new_item->key = 0;
new_item->name[0] = 0;
new_item->start_time = 0;
......
......@@ -7,12 +7,13 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_data.c,v 1.59 2008-03-24 20:29:28 mtheo Exp $
* $Id: nmxp_data.c,v 1.60 2008-03-28 13:21:24 mtheo Exp $
*
*/
#include "nmxp_data.h"
#include "nmxp_log.h"
#include "nmxp_memory.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -698,7 +699,7 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *p
msr->sampletype = 'i'; /* declare type to be 32-bit integers */
msr->numsamples = pd->nSamp;
msr->datasamples = malloc (sizeof(int) * (msr->numsamples));
msr->datasamples = NMXP_MEM_MALLOC (sizeof(int) * (msr->numsamples));
memcpy(msr->datasamples, pd->pDataPtr, sizeof(int) * pd->nSamp); /* pointer to 32-bit integer data samples */
msr_srcname (msr, data_seed->srcname, 0);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_memory.c,v 1.1 2008-03-28 11:47:06 mtheo Exp $
* $Id: nmxp_memory.c,v 1.2 2008-03-28 13:21:24 mtheo Exp $
*
*/
......@@ -30,7 +30,7 @@ typedef struct {
struct timeval tv;
} NMXP_MEM_STRUCT;
#define MAX_MEM_STRUCTS 4096
#define MAX_MEM_STRUCTS (4096 * 16)
static NMXP_MEM_STRUCT nms[MAX_MEM_STRUCTS];
static int i_nms = 0;
......@@ -75,9 +75,10 @@ void nmxp_mem_print_ptr() {
i++;
}
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "tot %d\n", tot_size);
old_tot_size = tot_size;
}
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "nmxp_mem_print_ptr() tot %d\n", tot_size);
}
static int nmxp_mem_rem_ptr(void *ptr, struct timeval *tv, int *size) {
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.156 2008-03-28 11:44:46 mtheo Exp $
* $Id: nmxptool.c,v 1.157 2008-03-28 13:21:24 mtheo Exp $
*
*/
......@@ -220,6 +220,8 @@ int main (int argc, char **argv) {
nmxptool_log_params(&params);
nmxp_mem_print_ptr();
#ifdef HAVE_LIBMSEED
if(params.flag_writeseed) {
ms_loginit((void*)&nmxptool_log_miniseed, NULL, (void*)&nmxptool_logerr_miniseed, "error: ");
......@@ -250,7 +252,7 @@ int main (int argc, char **argv) {
/* Free the complete channel list */
if(channelList) {
free(channelList);
NMXP_MEM_FREE(channelList);
channelList = NULL;
}
......@@ -264,7 +266,7 @@ int main (int argc, char **argv) {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "Init channelList_Seq.\n");
/* init channelList_Seq */
channelList_Seq = (NMXPTOOL_CHAN_SEQ *) malloc(sizeof(NMXPTOOL_CHAN_SEQ) * channelList_subset->number);
channelList_Seq = (NMXPTOOL_CHAN_SEQ *) NMXP_MEM_MALLOC(sizeof(NMXPTOOL_CHAN_SEQ) * channelList_subset->number);
for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
channelList_Seq[i_chan].significant = 0;
channelList_Seq[i_chan].last_time = 0.0;
......@@ -624,7 +626,7 @@ int main (int argc, char **argv) {
/* Free pd->buffer */
if(pd->buffer) {
free(pd->buffer);
NMXP_MEM_FREE(pd->buffer);
pd->buffer = NULL;
}
......@@ -731,13 +733,13 @@ int main (int argc, char **argv) {
/* Free the complete channel list */
if(channelList) {
free(channelList);
NMXP_MEM_FREE(channelList);
channelList = NULL;
}
/* TODO check if channelList_subset_waste is equal to channelList_subset and free */
if(channelList_subset_waste) {
free(channelList_subset_waste);
NMXP_MEM_FREE(channelList_subset_waste);
channelList_subset_waste = NULL;
}
......@@ -931,7 +933,7 @@ int main (int argc, char **argv) {
}
/* Free pd->buffer */
if(pd->buffer) {
free(pd->buffer);
NMXP_MEM_FREE(pd->buffer);
pd->buffer = NULL;
}
}
......@@ -1013,24 +1015,28 @@ int main (int argc, char **argv) {
}
#endif
nmxp_mem_print_ptr();
if(channelList_Seq && channelList_subset) {
for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
nmxp_raw_stream_free(&(channelList_Seq[i_chan].raw_stream_buffer));
}
free(channelList_Seq);
NMXP_MEM_FREE(channelList_Seq);
channelList_Seq = NULL;
}
/* This has to be tha last */
if(channelList_subset) {
free(channelList_subset);
NMXP_MEM_FREE(channelList_subset);
channelList_subset = NULL;
}
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "return code %d\n", sigcondition);
nmxp_mem_print_ptr();
return sigcondition;
} /* End MAIN */
......@@ -1233,6 +1239,8 @@ static void clientShutdown(int sig) {
nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "%s interrupted by signal %d!\n", NMXP_LOG_STR(PACKAGE_NAME), sig);
nmxp_mem_print_ptr();
times_flow = TIMES_FLOW_EXIT;
sigcondition = sig;
......@@ -1299,6 +1307,8 @@ Channel Ind S x-1 LastTime LastTimeCallRaw Aft
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY, "Channel list is NULL!\n");
}
nmxp_mem_print_ptr();
}
#endif /* HAVE_WINDOWS_H */
......
......@@ -377,7 +377,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
MAXADDRLEN);
return EW_FAILURE;
}
params->hostname = strdup(str);
params->hostname = NMXP_MEM_STRDUP(str);
}
}
......@@ -391,13 +391,13 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
else if (k_its ("UserDAP")) {
if ( (str = k_str ()) ) {
params->datas_username = strdup(str);
params->datas_username = NMXP_MEM_STRDUP(str);
}
}
else if (k_its ("PassDAP")) {
if ( (str = k_str ()) ) {
params->datas_password = strdup(str);
params->datas_password = NMXP_MEM_STRDUP(str);
}
}
......@@ -423,7 +423,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
fprintf(stderr, "DefaultNetworkCode has been replicated!\n");
return EW_FAILURE;
} else {
params->network = strdup(str);
params->network = NMXP_MEM_STRDUP(str);
}
}
}
......@@ -437,7 +437,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
}
if(!params->channels) {
#define MAXSIZECHANNELSTRING 8000
params->channels = (char *) malloc (MAXSIZECHANNELSTRING);
params->channels = (char *) NMXP_MEM_MALLOC(MAXSIZECHANNELSTRING);
strncpy(params->channels, str, MAXSIZECHANNELSTRING);
} else {
strncat(params->channels, ",", MAXSIZECHANNELSTRING);
......@@ -467,7 +467,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
else if (k_its ("ChannelFile")) {
if ( (str = k_str ()) ) {
params->flag_buffered = 1;
params->statefile = (char *) malloc(512 * sizeof(char));
params->statefile = (char *) NMXP_MEM_MALLOC(512 * sizeof(char));
strncpy(params->statefile, str, 512);
if(params->channels == NULL) {
params->channels = get_channel_list_argument_from_state_file(params->statefile);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.c,v 1.92 2008-03-26 08:40:48 mtheo Exp $
* $Id: nmxptool_getoptlong.c,v 1.93 2008-03-28 13:21:24 mtheo Exp $
*
*/
......@@ -371,7 +371,7 @@ char *get_channel_list_argument_from_state_file(const char *filename) {
/* Read only channel names from state file */
if(fstatefile) {
ret_channel_string = (char *) malloc (MAXSIZECHANNELSTRINGARGUMENT);
ret_channel_string = (char *) NMXP_MEM_MALLOC(MAXSIZECHANNELSTRINGARGUMENT);
ret_channel_string[0] = 0;
while(fgets(line, MAXSIZE_LINE_CHAN_STATE, fstatefile) != NULL) {
k = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment