gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 2c7f064 3/4: NoiseChisel frees all major alloc


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2c7f064 3/4: NoiseChisel frees all major allocated memory
Date: Sun, 1 Oct 2017 21:51:33 -0400 (EDT)

branch: master
commit 2c7f0641cbc9c2c4b7746f53c93bc709720e7f25
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    NoiseChisel frees all major allocated memory
    
    While running NoiseChisel with mmap, I noticed that there were two
    `gnuastro/mmap_*' files remaining after NoiseChisel finished. So using
    Valgrind (and without using `mmap'), the memory allocations/freeing were
    checked and the necessary freeing was done in the proper places. Currently
    there are only some small bytes that are not freed in the WCS structure
    which I believe is because WCSLIB is not properly freeing.
---
 bin/noisechisel/detection.c | 7 +++++--
 bin/noisechisel/ui.c        | 1 +
 lib/binary.c                | 3 +++
 lib/fits.c                  | 5 +++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/bin/noisechisel/detection.c b/bin/noisechisel/detection.c
index 39cde81..857dad3 100644
--- a/bin/noisechisel/detection.c
+++ b/bin/noisechisel/detection.c
@@ -936,12 +936,13 @@ detection_quantile_expand(struct noisechiselparams *p, 
gal_data_t *workbin)
   exp_thresh_full=gal_tile_block_write_const_value(p->expand_thresh,
                                                    p->cp.tl.tiles, 0, 0);
 
+
   /* Count the pixels that must be expanded. */
   e_th=exp_thresh_full->array;
   do { if(*b++==0 && *arr>*e_th) ++counter; ++arr; ++e_th; } while(b<bf);
 
-  /* Allocate the space necessary to keep all the index of all the pixels
-     that must be expanded and re-initialize the necessary pointers. */
+  /* Allocate the space necessary to keep the index of all the pixels that
+     must be expanded and re-initialize the necessary pointers. */
   diffuseindexs=gal_data_alloc(NULL, GAL_TYPE_SIZE_T, 1, &counter, NULL, 0,
                                p->cp.minmapsize, NULL, NULL, NULL);
 
@@ -1001,7 +1002,9 @@ detection_quantile_expand(struct noisechiselparams *p, 
gal_data_t *workbin)
     }
 
   /* Clean up and return */
+  gal_data_free(p->expand_thresh);
   gal_data_free(exp_thresh_full);
+  gal_data_free(diffuseindexs);
   return numexpanded;
 }
 
diff --git a/bin/noisechisel/ui.c b/bin/noisechisel/ui.c
index 09f0d9d..96731ff 100644
--- a/bin/noisechisel/ui.c
+++ b/bin/noisechisel/ui.c
@@ -771,6 +771,7 @@ ui_free_report(struct noisechiselparams *p, struct timeval 
*t1)
   /* Free the simply allocated spaces. */
   free(p->cp.hdu);
   free(p->maxtsize);
+  free(p->maxltsize);
   free(p->cp.output);
   if(p->skyname)          free(p->skyname);
   if(p->detskyname)       free(p->detskyname);
diff --git a/lib/binary.c b/lib/binary.c
index 4e5ba3e..ddadb21 100644
--- a/lib/binary.c
+++ b/lib/binary.c
@@ -685,6 +685,9 @@ gal_binary_fill_holes(gal_data_t *input, int connectivity, 
size_t maxsize)
       do
         if(*i!=GAL_BLANK_INT32) *i = sizes[*i]>maxsize ? 1 : *i;
       while(++i<fi);
+
+      /* Clean up. */
+      free(sizes);
     }
 
   /* The type of the tile is already known (it is `int32_t') and we have no
diff --git a/lib/fits.c b/lib/fits.c
index b0f901e..f56a13c 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -1435,9 +1435,11 @@ gal_fits_img_info(fitsfile *fptr, int *type, size_t 
*ndim, size_t **dsize,
     gal_fits_io_error(status, NULL);
   *ndim=naxis;
 
+
   /* Convert bitpix to Gnuastro's known types. */
   *type=gal_fits_bitpix_to_type(bitpix);
 
+
   /* Define the names of the possibly existing important keywords about the
      dataset. We are defining these in the opposite order to be read by
      CFITSIO. The way Gnuastro writes the FITS keywords, the output will
@@ -1476,6 +1478,8 @@ gal_fits_img_info(fitsfile *fptr, int *type, size_t 
*ndim, size_t **dsize,
       ++i;
     }
 
+
+  /* If a type correction is necessary, then do it. */
   if( !isnan(bscale) || bzero_str )
     fits_type_correct(type, bscale, bzero_str);
 
@@ -1489,6 +1493,7 @@ gal_fits_img_info(fitsfile *fptr, int *type, size_t 
*ndim, size_t **dsize,
 
   /* Clean up. */
   gal_list_data_free(keysll);
+  if(bzero_str) free(bzero_str);
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]