[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master b1ac8634 1/3: Book (wcs.h): no memory leak aft
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master b1ac8634 1/3: Book (wcs.h): no memory leak after gal_wcs_create |
Date: |
Thu, 29 Sep 2022 12:27:59 -0400 (EDT) |
branch: master
commit b1ac86344533bfddaf45cd6ff89a71b23d987fa1
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Book (wcs.h): no memory leak after gal_wcs_create
Until now, gal_wcs_create only instructed creating a wcs struct.
With this commit, instruct the library users to free the created wcs struct
using the 'wcsfree' function and the pointer with 'free'.
---
doc/gnuastro.texi | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index cb5c5ec6..1f8e3f1b 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -33279,6 +33279,28 @@ All the arrays must have @code{ndim} elements with
them except for @code{pc} whi
Also, @code{cunit} and @code{ctype} are arrays of strings.
If @code{GAL_WCS_LINEAR_MATRIX_CD} is passed to @code{linearmatrix} then the
output WCS structure will have a CD matrix (even though you have given a PC and
CDELT matrix as input to this function).
Otherwise, the output will have a PC and CDELT matrix (which is the
recommended format by WCSLIB).
+
+To prevent memory-leak, free the WCS structure first by WCSLIB's
@code{wcsfree} function, and then the pointer with @code{stdlib.h}'s
@code{free} when the process is finished:
+
+@example
+@verbatim
+int status;
+size_t ndim=2;
+double crpix[]={50, 50};
+double pc[]={-1, 0, 0, 1};
+double cdelt[]={0.4, 0.4};
+double crval[]={178.23, 36.98};
+char *cunit[]={"deg", "deg"};
+char *ctype[]={"RA---TAN", "DEC--TAN"};
+int linearmatrix = GAL_WCS_LINEAR_MATRIX_PC;
+struct wcsprm *wcsp =
+ gal_wcs_create(crpix, crval, cdelt, pc, cunit,
+ ctype, ndim, linearmatrix);
+status = wcsfree(wcsp);
+free(wcsp);
+@end verbatim
+@end example
+
@end deftypefun
@deftypefun {char *} gal_wcs_dimension_name (struct wcsprm @code{*wcs}, size_t
@code{dimension})