[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 069d7a4: Statistics: fixed 2D histogram segmen
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 069d7a4: Statistics: fixed 2D histogram segmentation fault |
Date: |
Wed, 6 Jan 2021 06:55:42 -0500 (EST) |
branch: master
commit 069d7a4ed14d5ce91f91e3f6bb1ce2a35fd9dcdb
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Statistics: fixed 2D histogram segmentation fault
Until now when the input columns didn't have units, the 2D histogram
feature of Statistics would crash when creating the WCS.
With this commit a condition has been added to not assume units when
creating the WCS, and only use them when one is defined. Also, following
this check, I noticed several memory leakage situations throughout
statistics (and in the WCS library) that have now been fixed.
This bug was reported by Samane Raji.
---
bin/statistics/statistics.c | 8 ++++++--
bin/statistics/ui.c | 13 ++++++++++---
lib/data.c | 3 ++-
lib/wcs.c | 9 ++++++---
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index 53a41b0..c2009fa 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -515,8 +515,8 @@ set_bin_range_params(struct statisticsparams *p, size_t dim)
if(p->manualbinrange)
{
/* Allocate the range data structure. */
- range=gal_data_alloc(NULL, GAL_TYPE_FLOAT32, 1, &rsize, NULL, 0, -1, 1,
- NULL, NULL, NULL);
+ range=gal_data_alloc(NULL, GAL_TYPE_FLOAT32, 1, &rsize, NULL,
+ 0, -1, 1, NULL, NULL, NULL);
switch(dim)
{
case 1:
@@ -562,6 +562,7 @@ ascii_plots(struct statisticsparams *p)
/* Clean up.*/
gal_data_free(bins);
gal_data_free(hist);
+ gal_data_free(range);
if(p->asciicfp) gal_data_free(cfp);
}
@@ -816,6 +817,9 @@ histogram_2d(struct statisticsparams *p)
write_output_table(p, hist2d, suf, contents);
/* Clean up. */
+ gal_data_free(range1);
+ gal_data_free(range2);
+ gal_list_data_free(bins);
gal_list_data_free(hist2d);
}
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index 7a123ac..d8ce160 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -670,6 +670,7 @@ ui_out_of_range_to_blank(struct statisticsparams *p)
break;
case 2:
cond = gal_arithmetic(GAL_ARITHMETIC_OP_OR, 1, flagsor, cond_l, cond_g);
+ gal_data_free(cond_g);
break;
}
@@ -780,6 +781,9 @@ ui_read_columns_in_one(gal_list_str_t *incolumns)
/* Add each array element to the final list of columns. */
for(i=0;i<strs->size;++i)
gal_list_str_add(&final, strarr[i], 1);
+
+ /* Clean up. */
+ gal_data_free(strs);
}
/* Reverse the list to be in the same order. */
@@ -1014,8 +1018,8 @@ ui_preparations(struct statisticsparams *p)
{
gal_checkset_writable_remove(tl->tilecheckname, 0,
cp->dontdelete);
- gal_table_write(check, NULL, NULL, cp->tableformat,
tl->tilecheckname,
- "TABLE", 0);
+ gal_table_write(check, NULL, NULL, cp->tableformat,
+ tl->tilecheckname, "TABLE", 0);
}
gal_data_free(check);
}
@@ -1049,6 +1053,9 @@ ui_preparations(struct statisticsparams *p)
p->input->next->flag &= ~GAL_DATA_FLAG_HASBLANK ;
p->input->next->flag |= GAL_DATA_FLAG_BLANK_CH ;
+
+ gal_data_free(flag1);
+ gal_data_free(flag2);
}
else
gal_blank_remove(p->input);
@@ -1188,8 +1195,8 @@ ui_free_report(struct statisticsparams *p)
/* Free the allocated arrays: */
free(p->cp.hdu);
free(p->cp.output);
- gal_data_free(p->input);
gal_data_free(p->reference);
+ gal_list_data_free(p->input);
gal_list_f64_free(p->tp_args);
gal_list_i32_free(p->singlevalue);
gal_tile_full_free_contents(&p->cp.tl);
diff --git a/lib/data.c b/lib/data.c
index e9e3034..ab1c762 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -237,8 +237,9 @@ gal_data_free_contents(gal_data_t *data)
if(data->name) { free(data->name); data->name = NULL; }
if(data->unit) { free(data->unit); data->unit = NULL; }
if(data->dsize) { free(data->dsize); data->dsize = NULL; }
- if(data->wcs) { wcsfree(data->wcs); data->wcs = NULL; }
if(data->comment) { free(data->comment); data->comment = NULL; }
+ if(data->wcs)
+ { wcsfree(data->wcs); free(data->wcs); data->wcs = NULL; }
/* If the data type is string, then each element in the array is actually
a pointer to the array of characters, so free them before freeing the
diff --git a/lib/wcs.c b/lib/wcs.c
index 72e56db..06a8295 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -405,8 +405,8 @@ gal_wcs_create(double *crpix, double *crval, double *cdelt,
wcs->crpix[i] = crpix[i];
wcs->crval[i] = crval[i];
wcs->cdelt[i] = cdelt[i];
- strcpy(wcs->cunit[i], cunit[i]);
- strcpy(wcs->ctype[i], ctype[i]);
+ if(cunit[i]) strcpy(wcs->cunit[i], cunit[i]);
+ if(ctype[i]) strcpy(wcs->ctype[i], ctype[i]);
}
for(i=0;i<ndim*ndim;++i) wcs->pc[i]=pc[i];
@@ -491,7 +491,10 @@ gal_wcs_write_in_fitsptr(fitsfile *fptr, struct wcsprm
*wcs)
error(0, 0, "%s: WARNING: WCSLIB error, no WCS in output.\n"
"wcshdu ERROR %d: %s", __func__, status, wcs_errmsg[status]);
else
- gal_fits_key_write_wcsstr(fptr, wcsstr, nkeyrec);
+ {
+ gal_fits_key_write_wcsstr(fptr, wcsstr, nkeyrec);
+ free(wcsstr);
+ }
status=0;
/* WCSLIB is going to write PC+CDELT keywords in any case. But when we
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 069d7a4: Statistics: fixed 2D histogram segmentation fault,
Mohammad Akhlaghi <=