Update fstapi.c to remove redundant if checks before a free.
Free accepts a NULL argument so there is not need to check that a variable is defined before calling free.
This commit is contained in:
parent
32e29e394d
commit
51beee970b
79
vpi/fstapi.c
79
vpi/fstapi.c
|
|
@ -555,7 +555,7 @@ if(!xc->curval_mem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void fstDestroyMmaps(struct fstWriterContext *xc)
|
static void fstDestroyMmaps(struct fstWriterContext *xc, int is_closing)
|
||||||
{
|
{
|
||||||
if(xc->valpos_mem)
|
if(xc->valpos_mem)
|
||||||
{
|
{
|
||||||
|
|
@ -564,6 +564,24 @@ if(xc->valpos_mem)
|
||||||
}
|
}
|
||||||
if(xc->curval_mem)
|
if(xc->curval_mem)
|
||||||
{
|
{
|
||||||
|
#if defined __CYGWIN__ || defined __MINGW32__
|
||||||
|
if(!is_closing) /* need to flush out for next emulated mmap() read */
|
||||||
|
{
|
||||||
|
unsigned char *pnt = xc->curval_mem;
|
||||||
|
int __fd = fileno(xc->curval_handle);
|
||||||
|
off_t cur_offs = lseek(__fd, 0, SEEK_CUR);
|
||||||
|
size_t i;
|
||||||
|
size_t __len = xc->maxvalpos;
|
||||||
|
|
||||||
|
lseek(__fd, 0, SEEK_SET);
|
||||||
|
for(i=0;i<__len;i+=SSIZE_MAX)
|
||||||
|
{
|
||||||
|
write(__fd, pnt + i, ((__len - i) >= SSIZE_MAX) ? SSIZE_MAX : (__len - i));
|
||||||
|
}
|
||||||
|
lseek(__fd, cur_offs, SEEK_SET);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
fstMunmap(xc->curval_mem, xc->maxvalpos);
|
fstMunmap(xc->curval_mem, xc->maxvalpos);
|
||||||
xc->curval_mem = NULL;
|
xc->curval_mem = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -650,7 +668,7 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
|
||||||
}
|
}
|
||||||
fstWriterFlushContext(xc);
|
fstWriterFlushContext(xc);
|
||||||
}
|
}
|
||||||
fstDestroyMmaps(xc);
|
fstDestroyMmaps(xc, 1);
|
||||||
|
|
||||||
/* write out geom section */
|
/* write out geom section */
|
||||||
fflush(xc->geom_handle);
|
fflush(xc->geom_handle);
|
||||||
|
|
@ -860,8 +878,7 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(xc->filename) { free(xc->filename); xc->filename = NULL; }
|
free(xc->filename); xc->filename = NULL;
|
||||||
|
|
||||||
free(xc);
|
free(xc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1405,7 +1422,7 @@ if(xc && nam)
|
||||||
{
|
{
|
||||||
if(xc->valpos_mem)
|
if(xc->valpos_mem)
|
||||||
{
|
{
|
||||||
fstDestroyMmaps(xc);
|
fstDestroyMmaps(xc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fputc(vt, xc->hier_handle);
|
fputc(vt, xc->hier_handle);
|
||||||
|
|
@ -1748,7 +1765,7 @@ static void fstReaderDeallocateScopeData(struct fstReaderContext *xc)
|
||||||
{
|
{
|
||||||
struct fstCurrHier *chp;
|
struct fstCurrHier *chp;
|
||||||
|
|
||||||
if(xc->curr_flat_hier_nam) { free(xc->curr_flat_hier_nam); xc->curr_flat_hier_nam = NULL; }
|
free(xc->curr_flat_hier_nam); xc->curr_flat_hier_nam = NULL;
|
||||||
while(xc->curr_hier)
|
while(xc->curr_hier)
|
||||||
{
|
{
|
||||||
chp = xc->curr_hier->prev;
|
chp = xc->curr_hier->prev;
|
||||||
|
|
@ -2385,10 +2402,10 @@ if(fv)
|
||||||
xc->maxhandle = 0;
|
xc->maxhandle = 0;
|
||||||
xc->num_alias = 0;
|
xc->num_alias = 0;
|
||||||
|
|
||||||
if(xc->signal_lens) free(xc->signal_lens);
|
free(xc->signal_lens);
|
||||||
xc->signal_lens = malloc(num_signal_dyn*sizeof(uint32_t));
|
xc->signal_lens = malloc(num_signal_dyn*sizeof(uint32_t));
|
||||||
|
|
||||||
if(xc->signal_typs) free(xc->signal_typs);
|
free(xc->signal_typs);
|
||||||
xc->signal_typs = malloc(num_signal_dyn*sizeof(unsigned char));
|
xc->signal_typs = malloc(num_signal_dyn*sizeof(unsigned char));
|
||||||
|
|
||||||
fseeko(xc->fh, 0, SEEK_SET);
|
fseeko(xc->fh, 0, SEEK_SET);
|
||||||
|
|
@ -2501,10 +2518,10 @@ if(fv) fprintf(fv, "$enddefinitions $end\n");
|
||||||
xc->signal_lens = realloc(xc->signal_lens, xc->maxhandle*sizeof(uint32_t));
|
xc->signal_lens = realloc(xc->signal_lens, xc->maxhandle*sizeof(uint32_t));
|
||||||
xc->signal_typs = realloc(xc->signal_typs, xc->maxhandle*sizeof(unsigned char));
|
xc->signal_typs = realloc(xc->signal_typs, xc->maxhandle*sizeof(unsigned char));
|
||||||
|
|
||||||
if(xc->process_mask) { free(xc->process_mask); }
|
free(xc->process_mask);
|
||||||
xc->process_mask = calloc(1, (xc->maxhandle+7)/8);
|
xc->process_mask = calloc(1, (xc->maxhandle+7)/8);
|
||||||
|
|
||||||
if(xc->temp_signal_value_buf) free(xc->temp_signal_value_buf);
|
free(xc->temp_signal_value_buf);
|
||||||
xc->temp_signal_value_buf = malloc(xc->longest_signal_value_len + 1);
|
xc->temp_signal_value_buf = malloc(xc->longest_signal_value_len + 1);
|
||||||
|
|
||||||
xc->var_count = xc->maxhandle + xc->num_alias;
|
xc->var_count = xc->maxhandle + xc->num_alias;
|
||||||
|
|
@ -2662,7 +2679,7 @@ while(blkpos < endfile)
|
||||||
xc->maxhandle = fstReaderUint64(xc->f);
|
xc->maxhandle = fstReaderUint64(xc->f);
|
||||||
xc->longest_signal_value_len = 32; /* arbitrarily set at 32...this is much longer than an expanded double */
|
xc->longest_signal_value_len = 32; /* arbitrarily set at 32...this is much longer than an expanded double */
|
||||||
|
|
||||||
if(xc->process_mask) { free(xc->process_mask); }
|
free(xc->process_mask);
|
||||||
xc->process_mask = calloc(1, (xc->maxhandle+7)/8);
|
xc->process_mask = calloc(1, (xc->maxhandle+7)/8);
|
||||||
|
|
||||||
if(clen != uclen)
|
if(clen != uclen)
|
||||||
|
|
@ -2688,9 +2705,9 @@ while(blkpos < endfile)
|
||||||
fstFread(ucdata, uclen, 1, xc->f);
|
fstFread(ucdata, uclen, 1, xc->f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xc->signal_lens) free(xc->signal_lens);
|
free(xc->signal_lens);
|
||||||
xc->signal_lens = malloc(sizeof(uint32_t) * xc->maxhandle);
|
xc->signal_lens = malloc(sizeof(uint32_t) * xc->maxhandle);
|
||||||
if(xc->signal_typs) free(xc->signal_typs);
|
free(xc->signal_typs);
|
||||||
xc->signal_typs = malloc(sizeof(unsigned char) * xc->maxhandle);
|
xc->signal_typs = malloc(sizeof(unsigned char) * xc->maxhandle);
|
||||||
|
|
||||||
for(i=0;i<xc->maxhandle;i++)
|
for(i=0;i<xc->maxhandle;i++)
|
||||||
|
|
@ -2717,7 +2734,7 @@ while(blkpos < endfile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xc->temp_signal_value_buf) free(xc->temp_signal_value_buf);
|
free(xc->temp_signal_value_buf);
|
||||||
xc->temp_signal_value_buf = malloc(xc->longest_signal_value_len + 1);
|
xc->temp_signal_value_buf = malloc(xc->longest_signal_value_len + 1);
|
||||||
|
|
||||||
free(ucdata);
|
free(ucdata);
|
||||||
|
|
@ -2735,9 +2752,9 @@ while(blkpos < endfile)
|
||||||
uint64_t delta;
|
uint64_t delta;
|
||||||
|
|
||||||
xc->num_blackouts = fstReaderVarint32(xc->f);
|
xc->num_blackouts = fstReaderVarint32(xc->f);
|
||||||
if(xc->blackout_times) free(xc->blackout_times);
|
free(xc->blackout_times);
|
||||||
xc->blackout_times = calloc(xc->num_blackouts, sizeof(uint64_t));
|
xc->blackout_times = calloc(xc->num_blackouts, sizeof(uint64_t));
|
||||||
if(xc->blackout_activity) free(xc->blackout_activity);
|
free(xc->blackout_activity);
|
||||||
xc->blackout_activity = calloc(xc->num_blackouts, sizeof(unsigned char));
|
xc->blackout_activity = calloc(xc->num_blackouts, sizeof(unsigned char));
|
||||||
|
|
||||||
for(i=0;i<xc->num_blackouts;i++)
|
for(i=0;i<xc->num_blackouts;i++)
|
||||||
|
|
@ -2818,11 +2835,11 @@ static void fstReaderDeallocateRvatData(void *ctx)
|
||||||
struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
|
struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
|
||||||
if(xc)
|
if(xc)
|
||||||
{
|
{
|
||||||
if(xc->rvat_chain_mem) { free(xc->rvat_chain_mem); xc->rvat_chain_mem = NULL; }
|
free(xc->rvat_chain_mem); xc->rvat_chain_mem = NULL;
|
||||||
if(xc->rvat_frame_data) { free(xc->rvat_frame_data); xc->rvat_frame_data = NULL; }
|
free(xc->rvat_frame_data); xc->rvat_frame_data = NULL;
|
||||||
if(xc->rvat_time_table) { free(xc->rvat_time_table); xc->rvat_time_table = NULL; }
|
free(xc->rvat_time_table); xc->rvat_time_table = NULL;
|
||||||
if(xc->rvat_chain_table) { free(xc->rvat_chain_table); xc->rvat_chain_table = NULL; }
|
free(xc->rvat_chain_table); xc->rvat_chain_table = NULL;
|
||||||
if(xc->rvat_chain_table_lengths) { free(xc->rvat_chain_table_lengths); xc->rvat_chain_table_lengths = NULL; }
|
free(xc->rvat_chain_table_lengths); xc->rvat_chain_table_lengths = NULL;
|
||||||
|
|
||||||
xc->rvat_data_valid = 0;
|
xc->rvat_data_valid = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -2837,15 +2854,15 @@ if(xc)
|
||||||
{
|
{
|
||||||
fstReaderDeallocateScopeData(xc);
|
fstReaderDeallocateScopeData(xc);
|
||||||
fstReaderDeallocateRvatData(xc);
|
fstReaderDeallocateRvatData(xc);
|
||||||
if(xc->rvat_sig_offs) { free(xc->rvat_sig_offs); xc->rvat_sig_offs = NULL; }
|
free(xc->rvat_sig_offs); xc->rvat_sig_offs = NULL;
|
||||||
|
|
||||||
if(xc->process_mask) { free(xc->process_mask); xc->process_mask = NULL; }
|
free(xc->process_mask); xc->process_mask = NULL;
|
||||||
if(xc->blackout_times) { free(xc->blackout_times); xc->blackout_times = NULL; }
|
free(xc->blackout_times); xc->blackout_times = NULL;
|
||||||
if(xc->blackout_activity) { free(xc->blackout_activity); xc->blackout_activity = NULL; }
|
free(xc->blackout_activity); xc->blackout_activity = NULL;
|
||||||
if(xc->temp_signal_value_buf) { free(xc->temp_signal_value_buf); xc->temp_signal_value_buf = NULL; }
|
free(xc->temp_signal_value_buf); xc->temp_signal_value_buf = NULL;
|
||||||
if(xc->signal_typs) { free(xc->signal_typs); xc->signal_typs = NULL; }
|
free(xc->signal_typs); xc->signal_typs = NULL;
|
||||||
if(xc->signal_lens) { free(xc->signal_lens); xc->signal_lens = NULL; }
|
free(xc->signal_lens); xc->signal_lens = NULL;
|
||||||
if(xc->filename) { free(xc->filename); xc->filename = NULL; }
|
free(xc->filename); xc->filename = NULL;
|
||||||
|
|
||||||
if(xc->fh)
|
if(xc->fh)
|
||||||
{
|
{
|
||||||
|
|
@ -3014,7 +3031,7 @@ for(;;)
|
||||||
fstFread(ucdata, tsec_uclen, 1, xc->f);
|
fstFread(ucdata, tsec_uclen, 1, xc->f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(time_table) free(time_table);
|
free(time_table);
|
||||||
time_table = calloc(tsec_nitems, sizeof(uint64_t));
|
time_table = calloc(tsec_nitems, sizeof(uint64_t));
|
||||||
tpnt = ucdata;
|
tpnt = ucdata;
|
||||||
tpval = 0;
|
tpval = 0;
|
||||||
|
|
@ -3629,7 +3646,7 @@ if(chain_table)
|
||||||
free(chain_table_lengths);
|
free(chain_table_lengths);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(time_table) free(time_table);
|
free(time_table);
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue