gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 29f8b20 16/19: Table and Arithmetic: corrected


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 29f8b20 16/19: Table and Arithmetic: corrected some memory leaks
Date: Sun, 14 Nov 2021 20:41:00 -0500 (EST)

branch: master
commit 29f8b205493bbcfdab97f206cc7e86e04a2e2f37
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Table and Arithmetic: corrected some memory leaks
    
    Until now, the Table and Arithmetic programs had some memory leaks (not
    freeing some allocated space by the time the program finished). Although
    they were very minor, it was important to find and fix them.
    
    With this commit they have been freed at the end of the respective program.
---
 bin/arithmetic/ui.c |  1 +
 bin/table/ui.c      |  3 +++
 lib/fits.c          | 13 +++++++------
 lib/options.c       | 14 +++++++-------
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index 80d2874..35f4b82 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -509,6 +509,7 @@ freeandreport(struct arithmeticparams *p, struct timeval 
*t1)
 {
   /* Free the simple strings. */
   free(p->cp.output);
+  if(p->wcshdu) free(p->wcshdu);
   if(p->globalhdu) free(p->globalhdu);
 
   /* If there are any remaining HDUs in the hdus linked list, then
diff --git a/bin/table/ui.c b/bin/table/ui.c
index f1aa8b8..aa07616 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -1304,9 +1304,12 @@ ui_free_report(struct tableparams *p)
   free(p->cp.output);
   ui_outcols_free(p->outcols);
   gal_list_data_free(p->table);
+  if(p->wcshdu) free(p->wcshdu);
   gal_list_str_free(p->columns, 1);
   if(p->colarray) free(p->colarray);
   gal_list_data_free(p->colmetadata);
+  gal_list_str_free(p->catcolumnhdu, 1);
+  gal_list_str_free(p->catcolumnfile, 1);
 
   /* If a random number generator was allocated, free it. */
   if(p->rng) gsl_rng_free(p->rng);
diff --git a/lib/fits.c b/lib/fits.c
index 93e2e7d..d61fc9d 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -3847,8 +3847,8 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
*comments,
   gal_data_t *col;
   size_t i, numrows=-1;
   gal_list_str_t *strt;
-  char **ttype, **tform, **tunit;
   int tbltype, numcols=0, status=0;
+  char **ttype, **tform, **tunit, **strarr;
 
   /* Make sure all the input columns have the same number of elements */
   for(col=cols; col!=NULL; col=col->next)
@@ -3918,11 +3918,12 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
*comments,
                          i+1, 1, 1, col->size, col->array, blank, &status);
       gal_fits_io_error(status, NULL);
 
-      /* Clean up and Increment the column counter. Note that unlike
-         reading a column from a table (in 'fits_tab_read_onecol'), the
-         'blank' value for strings here is directly the string, not a
-         pointer to a string. */
-      if(blank) free(blank);
+      /* Clean up and Increment the column counter. */
+      if(blank)
+        {
+          if(col->type==GAL_TYPE_STRING) {strarr=blank; free(strarr[0]);}
+          free(blank); blank=NULL;
+        }
       ++i;
     }
 
diff --git a/lib/options.c b/lib/options.c
index 5cdb50a..61115f6 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -1821,13 +1821,13 @@ gal_options_read_check(struct argp_option *option, char 
*arg, char *filename,
                           "  - It contains non-numerical characters.\n"
                           "  - It is negative, but the expected value is "
                           "positive.\n"
-                          "  - It is floating point, but the expected value "
-                          "is an integer.\n"
-                          "  - The previous option required a value, but you "
-                          "forgot to give it one, so the next option's "
-                          "name(+value, if there are no spaces between them) "
-                          "is read as the value of the previous option.", arg,
-                          option->name);
+                          "  - It is floating point, but the expected "
+                          "value is an integer.\n"
+                          "  - The previous option required a value, but "
+                          "you forgot to give it one, so the next option's "
+                          "name(+value, if there are no spaces between "
+                          "them) is read as the value of the previous "
+                          "option.", arg, option->name);
 
           /* Do a sanity check on the value. */
           options_sanity_check(option, arg, filename, lineno);



reply via email to

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