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 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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>. ...@@ -988,6 +988,7 @@ Mail bug reports and suggestions to <quintiliani@ingv.it>.
#include "nmxp_base.h" #include "nmxp_base.h"
#include "nmxp_crc32.h" #include "nmxp_crc32.h"
#include "nmxp_memory.h"
#define NMXP_MAX_MSCHAN_MSEC 15000 #define NMXP_MAX_MSCHAN_MSEC 15000
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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.h"
#include "nmxp_memory.h"
#include "config.h" #include "config.h"
...@@ -79,7 +80,7 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) { ...@@ -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 nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList, int32_t shortTermCompletion, int32_t out_format, NMXP_BUFFER_FLAG buffer_flag) {
int ret; int ret;
int32_t buffer_length = 16 + (4 * channelList->number); 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; int32_t app, i, disp;
disp=0; disp=0;
...@@ -109,7 +110,7 @@ int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList ...@@ -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); ret = nmxp_sendMessage(isock, NMXP_MSG_ADDTIMESERIESCHANNELS, buffer, buffer_length);
if(buffer) { if(buffer) {
free(buffer); NMXP_MEM_FREE(buffer);
buffer = NULL; buffer = NULL;
} }
return ret; return ret;
...@@ -372,7 +373,7 @@ int nmxp_waitReady(int isock) { ...@@ -372,7 +373,7 @@ int nmxp_waitReady(int isock) {
if(length > 0) { if(length > 0) {
if(type == NMXP_MSG_TERMINATESUBSCRIPTION) { if(type == NMXP_MSG_TERMINATESUBSCRIPTION) {
char *str_msg = NULL; 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; int32_t reason;
memcpy(&reason, buf_app, sizeof(reason)); memcpy(&reason, buf_app, sizeof(reason));
reason = ntohl(reason); reason = ntohl(reason);
...@@ -383,7 +384,7 @@ int nmxp_waitReady(int isock) { ...@@ -383,7 +384,7 @@ int nmxp_waitReady(int isock) {
(reason == 0)? "Normal" : (reason == 1)? "Error" : (reason == 2)? "Timeout" : "Unknown", (reason == 0)? "Normal" : (reason == 1)? "Error" : (reason == 2)? "Timeout" : "Unknown",
str_msg); str_msg);
if(buf_app) { if(buf_app) {
free(buf_app); NMXP_MEM_FREE(buf_app);
buf_app = NULL; buf_app = NULL;
} }
/* Close the socket*/ /* Close the socket*/
...@@ -396,10 +397,10 @@ int nmxp_waitReady(int isock) { ...@@ -396,10 +397,10 @@ int nmxp_waitReady(int isock) {
app = ntohl(app); app = ntohl(app);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "value = %d\n", app); nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "value = %d\n", app);
} else { } 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); rc = nmxp_recv_ctrl(isock, buf_app, length, 0, &recv_errno);
if(buf_app) { if(buf_app) {
free(buf_app); NMXP_MEM_FREE(buf_app);
buf_app = NULL; buf_app = NULL;
} }
} }
...@@ -495,7 +496,7 @@ NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_ ...@@ -495,7 +496,7 @@ NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_
} }
if(channelList) { if(channelList) {
free(channelList); NMXP_MEM_FREE(channelList);
channelList = NULL; channelList = NULL;
} }
...@@ -696,7 +697,7 @@ void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_t ...@@ -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->max_pdlist_items = max_tolerable_latency * 4;
raw_stream_buffer->timeoutrecv = timeoutrecv; raw_stream_buffer->timeoutrecv = timeoutrecv;
raw_stream_buffer->n_pdlist = 0; 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++) { for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
raw_stream_buffer->pdlist[j] = NULL; raw_stream_buffer->pdlist[j] = NULL;
} }
...@@ -711,18 +712,18 @@ void nmxp_raw_stream_free(NMXP_RAW_STREAM_DATA *raw_stream_buffer) { ...@@ -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++) { for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
if(raw_stream_buffer->pdlist[j]) { if(raw_stream_buffer->pdlist[j]) {
if(raw_stream_buffer->pdlist[j]->buffer) { 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; raw_stream_buffer->pdlist[j]->buffer = NULL;
} }
if(raw_stream_buffer->pdlist[j]->pDataPtr) { 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; 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; raw_stream_buffer->pdlist[j] = NULL;
} }
} }
free(raw_stream_buffer->pdlist); NMXP_MEM_FREE(raw_stream_buffer->pdlist);
raw_stream_buffer->pdlist = NULL; 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 ...@@ -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 */ /* 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)); memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS));
if(a_pd->length > 0) { 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); memcpy(pd->buffer, a_pd->buffer, a_pd->length);
} else { } else {
pd->buffer = NULL; pd->buffer = NULL;
} }
if(a_pd->nSamp * sizeof(int) > 0) { 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)); memcpy(pd->pDataPtr, a_pd->pDataPtr, a_pd->nSamp * sizeof(int));
} else { } else {
pd->pDataPtr = NULL; pd->pDataPtr = NULL;
...@@ -830,15 +831,15 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int ...@@ -830,15 +831,15 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
/* Free handled packet */ /* Free handled packet */
if(p->pdlist[0]->buffer) { if(p->pdlist[0]->buffer) {
free(p->pdlist[0]->buffer); NMXP_MEM_FREE(p->pdlist[0]->buffer);
p->pdlist[0]->buffer = NULL; p->pdlist[0]->buffer = NULL;
} }
if(p->pdlist[0]->pDataPtr) { if(p->pdlist[0]->pDataPtr) {
free(p->pdlist[0]->pDataPtr); NMXP_MEM_FREE(p->pdlist[0]->pDataPtr);
p->pdlist[0]->pDataPtr = NULL; p->pdlist[0]->pDataPtr = NULL;
} }
if(p->pdlist[0]) { if(p->pdlist[0]) {
free(p->pdlist[0]); NMXP_MEM_FREE(p->pdlist[0]);
p->pdlist[0] = NULL; p->pdlist[0] = NULL;
} }
if(pd) { if(pd) {
...@@ -976,15 +977,15 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int ...@@ -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++) { for(k=0; k < p->n_pdlist; k++) {
if(k < j) { if(k < j) {
if(p->pdlist[k]->buffer) { if(p->pdlist[k]->buffer) {
free(p->pdlist[k]->buffer); NMXP_MEM_FREE(p->pdlist[k]->buffer);
p->pdlist[k]->buffer = NULL; p->pdlist[k]->buffer = NULL;
} }
if(p->pdlist[k]->pDataPtr) { if(p->pdlist[k]->pDataPtr) {
free(p->pdlist[k]->pDataPtr); NMXP_MEM_FREE(p->pdlist[k]->pDataPtr);
p->pdlist[k]->pDataPtr = NULL; p->pdlist[k]->pDataPtr = NULL;
} }
if(p->pdlist[k]) { if(p->pdlist[k]) {
free(p->pdlist[k]); NMXP_MEM_FREE(p->pdlist[k]);
p->pdlist[k] = NULL; p->pdlist[k] = NULL;
} }
} }
......
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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 "config.h"
#include "nmxp_base.h" #include "nmxp_base.h"
#include "nmxp_memory.h"
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
#include "nmxp_win.h" #include "nmxp_win.h"
#endif #endif
...@@ -402,7 +403,7 @@ int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t ...@@ -402,7 +403,7 @@ int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t
if( ret == NMXP_SOCKET_OK ) { if( ret == NMXP_SOCKET_OK ) {
if (*length > 0) { if (*length > 0) {
*buffer = malloc(*length); *buffer = NMXP_MEM_MALLOC(*length);
ret = nmxp_recv_ctrl(isock, *buffer, *length, 0, recv_errno); ret = nmxp_recv_ctrl(isock, *buffer, *length, 0, recv_errno);
if(*type == NMXP_MSG_TERMINATESUBSCRIPTION) { if(*type == NMXP_MSG_TERMINATESUBSCRIPTION) {
......
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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_chan.h"
#include "nmxp_base.h" #include "nmxp_base.h"
#include "nmxp_memory.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -30,7 +31,7 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio ...@@ -30,7 +31,7 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio
channel_code[0] = 0; channel_code[0] = 0;
network_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 '.' */ /* count '.' */
i=0; i=0;
while(i < strlen(tmp_name) && !errors) { 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 ...@@ -66,7 +67,7 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio
} }
if(tmp_name) { if(tmp_name) {
free(tmp_name); NMXP_MEM_FREE(tmp_name);
tmp_name = NULL; tmp_name = NULL;
} }
...@@ -256,7 +257,7 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat ...@@ -256,7 +257,7 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat
int chan_number = channelList->number; int chan_number = channelList->number;
int i_chan = 0; 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; ret_channelList->number = 0;
for (i_chan = 0; i_chan < chan_number; i_chan++) 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 ...@@ -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 = NULL;
char nmxp_channel_name_duplicated[50]; 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; ret_channelList->number = 0;
istalist = 0; istalist = 0;
...@@ -437,7 +438,7 @@ void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list) { ...@@ -437,7 +438,7 @@ void nmxp_meta_chan_free(NMXP_META_CHAN_LIST **chan_list) {
if(iter) { if(iter) {
iter_next = iter->next; iter_next = iter->next;
while(iter) { while(iter) {
free(iter); NMXP_MEM_FREE(iter);
iter = iter_next; iter = iter_next;
iter_next = 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 ...@@ -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; 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->key = 0;
new_item->name[0] = 0; new_item->name[0] = 0;
new_item->start_time = 0; new_item->start_time = 0;
......
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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_data.h"
#include "nmxp_log.h" #include "nmxp_log.h"
#include "nmxp_memory.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -698,7 +699,7 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *p ...@@ -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->sampletype = 'i'; /* declare type to be 32-bit integers */
msr->numsamples = pd->nSamp; 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 */ memcpy(msr->datasamples, pd->pDataPtr, sizeof(int) * pd->nSamp); /* pointer to 32-bit integer data samples */
msr_srcname (msr, data_seed->srcname, 0); msr_srcname (msr, data_seed->srcname, 0);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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 { ...@@ -30,7 +30,7 @@ typedef struct {
struct timeval tv; struct timeval tv;
} NMXP_MEM_STRUCT; } NMXP_MEM_STRUCT;
#define MAX_MEM_STRUCTS 4096 #define MAX_MEM_STRUCTS (4096 * 16)
static NMXP_MEM_STRUCT nms[MAX_MEM_STRUCTS]; static NMXP_MEM_STRUCT nms[MAX_MEM_STRUCTS];
static int i_nms = 0; static int i_nms = 0;
...@@ -75,9 +75,10 @@ void nmxp_mem_print_ptr() { ...@@ -75,9 +75,10 @@ void nmxp_mem_print_ptr() {
i++; i++;
} }
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_ANY, "tot %d\n", tot_size);
old_tot_size = 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) { static int nmxp_mem_rem_ptr(void *ptr, struct timeval *tv, int *size) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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) { ...@@ -220,6 +220,8 @@ int main (int argc, char **argv) {
nmxptool_log_params(&params); nmxptool_log_params(&params);
nmxp_mem_print_ptr();
#ifdef HAVE_LIBMSEED #ifdef HAVE_LIBMSEED
if(params.flag_writeseed) { if(params.flag_writeseed) {
ms_loginit((void*)&nmxptool_log_miniseed, NULL, (void*)&nmxptool_logerr_miniseed, "error: "); ms_loginit((void*)&nmxptool_log_miniseed, NULL, (void*)&nmxptool_logerr_miniseed, "error: ");
...@@ -250,7 +252,7 @@ int main (int argc, char **argv) { ...@@ -250,7 +252,7 @@ int main (int argc, char **argv) {
/* Free the complete channel list */ /* Free the complete channel list */
if(channelList) { if(channelList) {
free(channelList); NMXP_MEM_FREE(channelList);
channelList = NULL; channelList = NULL;
} }
...@@ -264,7 +266,7 @@ int main (int argc, char **argv) { ...@@ -264,7 +266,7 @@ int main (int argc, char **argv) {
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "Init channelList_Seq.\n"); nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "Init channelList_Seq.\n");
/* init channelList_Seq */ /* 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++) { for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
channelList_Seq[i_chan].significant = 0; channelList_Seq[i_chan].significant = 0;
channelList_Seq[i_chan].last_time = 0.0; channelList_Seq[i_chan].last_time = 0.0;
...@@ -624,7 +626,7 @@ int main (int argc, char **argv) { ...@@ -624,7 +626,7 @@ int main (int argc, char **argv) {
/* Free pd->buffer */ /* Free pd->buffer */
if(pd->buffer) { if(pd->buffer) {
free(pd->buffer); NMXP_MEM_FREE(pd->buffer);
pd->buffer = NULL; pd->buffer = NULL;
} }
...@@ -731,13 +733,13 @@ int main (int argc, char **argv) { ...@@ -731,13 +733,13 @@ int main (int argc, char **argv) {
/* Free the complete channel list */ /* Free the complete channel list */
if(channelList) { if(channelList) {
free(channelList); NMXP_MEM_FREE(channelList);
channelList = NULL; channelList = NULL;
} }
/* TODO check if channelList_subset_waste is equal to channelList_subset and free */ /* TODO check if channelList_subset_waste is equal to channelList_subset and free */
if(channelList_subset_waste) { if(channelList_subset_waste) {
free(channelList_subset_waste); NMXP_MEM_FREE(channelList_subset_waste);
channelList_subset_waste = NULL; channelList_subset_waste = NULL;
} }
...@@ -931,7 +933,7 @@ int main (int argc, char **argv) { ...@@ -931,7 +933,7 @@ int main (int argc, char **argv) {
} }
/* Free pd->buffer */ /* Free pd->buffer */
if(pd->buffer) { if(pd->buffer) {
free(pd->buffer); NMXP_MEM_FREE(pd->buffer);
pd->buffer = NULL; pd->buffer = NULL;
} }
} }
...@@ -1013,24 +1015,28 @@ int main (int argc, char **argv) { ...@@ -1013,24 +1015,28 @@ int main (int argc, char **argv) {
} }
#endif #endif
nmxp_mem_print_ptr();
if(channelList_Seq && channelList_subset) { if(channelList_Seq && channelList_subset) {
for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) { for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
nmxp_raw_stream_free(&(channelList_Seq[i_chan].raw_stream_buffer)); nmxp_raw_stream_free(&(channelList_Seq[i_chan].raw_stream_buffer));
} }
free(channelList_Seq); NMXP_MEM_FREE(channelList_Seq);
channelList_Seq = NULL; channelList_Seq = NULL;
} }
/* This has to be tha last */ /* This has to be tha last */
if(channelList_subset) { if(channelList_subset) {
free(channelList_subset); NMXP_MEM_FREE(channelList_subset);
channelList_subset = NULL; channelList_subset = NULL;
} }
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "return code %d\n", sigcondition); nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "return code %d\n", sigcondition);
nmxp_mem_print_ptr();
return sigcondition; return sigcondition;
} /* End MAIN */ } /* End MAIN */
...@@ -1233,6 +1239,8 @@ static void clientShutdown(int sig) { ...@@ -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_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; times_flow = TIMES_FLOW_EXIT;
sigcondition = sig; sigcondition = sig;
...@@ -1299,6 +1307,8 @@ Channel Ind S x-1 LastTime LastTimeCallRaw Aft ...@@ -1299,6 +1307,8 @@ Channel Ind S x-1 LastTime LastTimeCallRaw Aft
} else { } else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY, "Channel list is NULL!\n"); nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_ANY, "Channel list is NULL!\n");
} }
nmxp_mem_print_ptr();
} }
#endif /* HAVE_WINDOWS_H */ #endif /* HAVE_WINDOWS_H */
......
...@@ -377,7 +377,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) { ...@@ -377,7 +377,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
MAXADDRLEN); MAXADDRLEN);
return EW_FAILURE; 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) { ...@@ -391,13 +391,13 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
else if (k_its ("UserDAP")) { else if (k_its ("UserDAP")) {
if ( (str = k_str ()) ) { if ( (str = k_str ()) ) {
params->datas_username = strdup(str); params->datas_username = NMXP_MEM_STRDUP(str);
} }
} }
else if (k_its ("PassDAP")) { else if (k_its ("PassDAP")) {
if ( (str = k_str ()) ) { 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) { ...@@ -423,7 +423,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
fprintf(stderr, "DefaultNetworkCode has been replicated!\n"); fprintf(stderr, "DefaultNetworkCode has been replicated!\n");
return EW_FAILURE; return EW_FAILURE;
} else { } 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) { ...@@ -437,7 +437,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
} }
if(!params->channels) { if(!params->channels) {
#define MAXSIZECHANNELSTRING 8000 #define MAXSIZECHANNELSTRING 8000
params->channels = (char *) malloc (MAXSIZECHANNELSTRING); params->channels = (char *) NMXP_MEM_MALLOC(MAXSIZECHANNELSTRING);
strncpy(params->channels, str, MAXSIZECHANNELSTRING); strncpy(params->channels, str, MAXSIZECHANNELSTRING);
} else { } else {
strncat(params->channels, ",", MAXSIZECHANNELSTRING); strncat(params->channels, ",", MAXSIZECHANNELSTRING);
...@@ -467,7 +467,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) { ...@@ -467,7 +467,7 @@ int nmxptool_ew_proc_configfile (char * configfile, NMXPTOOL_PARAMS *params) {
else if (k_its ("ChannelFile")) { else if (k_its ("ChannelFile")) {
if ( (str = k_str ()) ) { if ( (str = k_str ()) ) {
params->flag_buffered = 1; 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); strncpy(params->statefile, str, 512);
if(params->channels == NULL) { if(params->channels == NULL) {
params->channels = get_channel_list_argument_from_state_file(params->statefile); params->channels = get_channel_list_argument_from_state_file(params->statefile);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy * Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it * 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)