From 3802d3df703ae75262c86187cad4d3bae745a9ca Mon Sep 17 00:00:00 2001 From: William Joye Date: Wed, 4 Oct 2017 13:07:35 -0400 Subject: track down memory leaks with getString --- tksao/fitsy++/block.C | 4 ++-- tksao/fitsy++/card.C | 22 +++++++++++++--------- tksao/fitsy++/card.h | 3 +++ tksao/fitsy++/column.C | 8 ++++---- tksao/fitsy++/compress.C | 14 +++++++------- tksao/fitsy++/file.C | 6 +++--- tksao/fitsy++/file.h | 2 +- tksao/fitsy++/hcompress.C | 2 +- tksao/fitsy++/hdu.C | 6 +++--- tksao/fitsy++/head.C | 14 +++++++------- tksao/fitsy++/head.h | 2 +- tksao/fitsy++/hist.C | 6 +++--- tksao/fitsy++/hpx.C | 2 +- tksao/fitsy++/map.C | 2 +- tksao/fitsy++/mapincr.C | 2 +- tksao/fitsy++/rice.C | 2 +- tksao/fitsy++/strm.C | 2 +- tksao/frame/fitscompress.C | 2 +- tksao/frame/fitshealpix.C | 4 ++-- tksao/frame/fitsimage.C | 44 ++++++++++++++++++++++---------------------- tksao/frame/frsave.C | 26 +++++++++++++------------- 21 files changed, 91 insertions(+), 84 deletions(-) diff --git a/tksao/fitsy++/block.C b/tksao/fitsy++/block.C index adf5f91..c8477ea 100644 --- a/tksao/fitsy++/block.C +++ b/tksao/fitsy++/block.C @@ -114,7 +114,7 @@ void FitsBlock::initHeader(FitsFile* fits, Vector& block) void FitsBlock::initCCDSUM(Vector& block) { if (head_->find("CCDSUM")) { - char* val = head_->getString("CCDSUM"); + char* val = head_->getStringCopy("CCDSUM"); float xx,yy; istringstream istr(val); istr >> xx >> yy; @@ -131,7 +131,7 @@ void FitsBlock::initCCDSUM(Vector& block) void FitsBlock::initKeySEC(const char* key, Vector& block) { if (head_->find(key)) { - char* sec = head_->getString(key); + char* sec = head_->getStringCopy(key); Vector ll,ur; parseSection(sec,&ll,&ur); Matrix mm = Translate(-1,-1) * diff --git a/tksao/fitsy++/card.C b/tksao/fitsy++/card.C index 46ecfe1..57351ce 100644 --- a/tksao/fitsy++/card.C +++ b/tksao/fitsy++/card.C @@ -203,9 +203,8 @@ void FitsCard::getComplex(double* r, double* i) char* FitsCard::getString() { - char value[FTY_CARDLEN]; - value[0] = '\0'; - value[FTY_CARDLEN-1] = '\0'; + buf_[0] = '\0'; + buf_[FTY_CARDLEN-1] = '\0'; int i,j; @@ -223,16 +222,21 @@ char* FitsCard::getString() else i++; } - value[j] = card_[i]; + buf_[j] = card_[i]; } // DON'T strip any spaces - // for (; j && value[j-1]==' '; j--); - value[j] = '\0'; + // for (; j && buf_[j-1]==' '; j--); + buf_[j] = '\0'; - // return result - char* cpy = new char[strlen(value)+1]; - strcpy(cpy, value); + return buf_; +} + +char* FitsCard::getStringCopy() +{ + getString(); + char* cpy = new char[strlen(buf_)+1]; + strcpy(cpy, buf_); return cpy; } diff --git a/tksao/fitsy++/card.h b/tksao/fitsy++/card.h index c5b5350..c12265b 100644 --- a/tksao/fitsy++/card.h +++ b/tksao/fitsy++/card.h @@ -18,6 +18,8 @@ class FitsCard { private: char* card_; int managed; + // only used to return pointer to internal string + char buf_[FTY_CARDLEN]; public: FitsCard(); @@ -62,6 +64,7 @@ public: double getReal(); void getComplex(double*, double*); char* getString(); + char* getStringCopy(); char* getComment(); char* getAsString(); }; diff --git a/tksao/fitsy++/column.C b/tksao/fitsy++/column.C index 4215957..9603182 100644 --- a/tksao/fitsy++/column.C +++ b/tksao/fitsy++/column.C @@ -24,9 +24,9 @@ FitsColumn::FitsColumn(FitsHead* head, int i, int off) offset_ = off; type_ = ' '; - tform_ = head->getString(keycat("TFORM",i)); - ttype_ = head->getString(keycat("TTYPE",i)); - tunit_ = head->getString(keycat("TUNIT",i)); + tform_ = head->getStringCopy(keycat("TFORM",i)); + ttype_ = head->getStringCopy(keycat("TTYPE",i)); + tunit_ = head->getStringCopy(keycat("TUNIT",i)); tscal_ = head->getReal(keycat("TSCAL",i), 1); tzero_ = head->getReal(keycat("TZERO",i), 0); hastnull_ = head->find(keycat("TNULL",i)) ? 1:0; @@ -183,7 +183,7 @@ template <> Vector FitsAsciiColumnT::dimension() FitsBinColumn::FitsBinColumn(FitsHead* head, int i, int offset) : FitsColumn(head, i, offset) { - tdisp_ = head->getString(keycat("TDISP",i)); + tdisp_ = head->getStringCopy(keycat("TDISP",i)); repeat_ = 1; if (tform_) { diff --git a/tksao/fitsy++/compress.C b/tksao/fitsy++/compress.C index 37d16c2..3bc1bc9 100644 --- a/tksao/fitsy++/compress.C +++ b/tksao/fitsy++/compress.C @@ -10,7 +10,7 @@ FitsCompress::FitsCompress(FitsFile* fits) { bitpix_ = fits->getInteger("ZBITPIX",0); - type_ = fits->getString("ZCMPTYPE"); + type_ = fits->getStringCopy("ZCMPTYPE"); // int naxes = fits->getInteger("ZNAXIS",0); width_ = fits->getInteger("ZNAXIS1",0); height_ = fits->getInteger("ZNAXIS2",0); @@ -23,12 +23,12 @@ FitsCompress::FitsCompress(FitsFile* fits) bscale_ = fits->getReal("ZSCALE",1); bzero_ = fits->getReal("ZZERO",0); blank_ = fits->getInteger("ZBLANK",0); - zmaskcmp_ = fits->getString("ZMASKCMP"); + zmaskcmp_ = fits->getStringCopy("ZMASKCMP"); quantize_ = NODITHER; char keyword[] = "ZQUANTIZ"; if (fits->find(keyword)) { - char* which = fits->getString(keyword); + char* which = fits->getStringCopy(keyword); if (!strncmp(which,"NONE",4)) quantize_ = NONE; if (!strncmp(which,"NO_DITHER",4)) @@ -97,7 +97,7 @@ int FitsCompress::initHeader(FitsFile* fits) // FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu()); if (srcHead->find("ZTENSION")) { - char* str = srcHead->getString("ZTENSION"); + char* str = srcHead->getStringCopy("ZTENSION"); head_ = new FitsHead(width_, height_, depth_, bitpix_, str); delete [] str; } @@ -153,7 +153,7 @@ int FitsCompress::initHeader(FitsFile* fits) // eat this one if (!strncmp(key,"EXTNAME",7)) { FitsCard cc(ptr); - char* str = cc.getString(); + char* str = cc.getStringCopy(); if (str) { if (!strncmp(str,"COMPRESSED_IMAGE",8)) { delete [] str; @@ -182,7 +182,7 @@ int FitsCompress::initHeader(FitsFile* fits) } if (!strncmp(key,"ZHECKSUM",8)) { FitsCard cc(ptr); - char* str = cc.getString(); + char* str = cc.getStringCopy(); if (str) { head_->appendString("CHECKSUM",str,NULL); delete [] str; @@ -191,7 +191,7 @@ int FitsCompress::initHeader(FitsFile* fits) } if (!strncmp(key,"ZDATASUM",8)) { FitsCard cc(ptr); - char* str = cc.getString(); + char* str = cc.getStringCopy(); if (str) { head_->appendString("DATASUM",str,NULL); delete [] str; diff --git a/tksao/fitsy++/file.C b/tksao/fitsy++/file.C index 74e9032..b871601 100644 --- a/tksao/fitsy++/file.C +++ b/tksao/fitsy++/file.C @@ -471,15 +471,15 @@ void FitsFile::getComplex(const char* name, double* real, double* img, *img = idef; } -char* FitsFile::getString(const char* name) +char* FitsFile::getStringCopy(const char* name) { if (head_) { - char* r = head_->getString(name); + char* r = head_->getStringCopy(name); if (r) return r; else if (primary_ && inherit_) - return primary_->getString(name); + return primary_->getStringCopy(name); } return NULL; diff --git a/tksao/fitsy++/file.h b/tksao/fitsy++/file.h index e410d92..f3e9c9d 100644 --- a/tksao/fitsy++/file.h +++ b/tksao/fitsy++/file.h @@ -212,7 +212,7 @@ public: double getReal(const char* name, double def); void getComplex(const char* name, double* real, double* img, double rdef, double idef); - char* getString(const char* name); + char* getStringCopy(const char* name); char* getComment(const char* name); char* getKeyword(const char* name); diff --git a/tksao/fitsy++/hcompress.C b/tksao/fitsy++/hcompress.C index 5ee0f6e..4a55398 100644 --- a/tksao/fitsy++/hcompress.C +++ b/tksao/fitsy++/hcompress.C @@ -30,7 +30,7 @@ template FitsHcompressm::FitsHcompressm(FitsFile* fits) name[5] = '0'+ii; val[4] = '0'+ii; if (fits->find(name)) { - char* which = fits->getString(name); + char* which = fits->getStringCopy(name); if (!strncmp(which,"SMOOTH",4)) smooth_ = fits->getInteger(val,4); delete [] which; diff --git a/tksao/fitsy++/hdu.C b/tksao/fitsy++/hdu.C index cb5646d..2c15e14 100644 --- a/tksao/fitsy++/hdu.C +++ b/tksao/fitsy++/hdu.C @@ -16,7 +16,7 @@ using namespace std; FitsHDU::FitsHDU(FitsHead* head) { - extname_ = head->getString("EXTNAME"); + extname_ = head->getStringCopy("EXTNAME"); // trim any spaces at end if (extname_) { for (int ii=strlen(extname_)-1; ii>=0; ii--) { @@ -210,7 +210,7 @@ FitsAsciiTableHDU::FitsAsciiTableHDU(FitsHead* head) : FitsTableHDU(head) size_t offset = 0; for (int i=0; igetString(keycat("TFORM",i+1)); + char* tform = head->getStringCopy(keycat("TFORM",i+1)); char type = 'F'; if (tform) { string x(tform); @@ -248,7 +248,7 @@ FitsBinTableHDU::FitsBinTableHDU(FitsHead* head) : FitsTableHDU(head) int offset =0; for (int i=0; igetString(keycat("TFORM",i+1)); + char* tform = head->getStringCopy(keycat("TFORM",i+1)); int repeat; char type = 'J'; if (tform) { diff --git a/tksao/fitsy++/head.C b/tksao/fitsy++/head.C index dc7a284..133abda 100644 --- a/tksao/fitsy++/head.C +++ b/tksao/fitsy++/head.C @@ -209,7 +209,7 @@ FitsHead::~FitsHead() int FitsHead::isImage() { // just look for SIMPLE, if present it may be of value 'F' - char* xtension = getString("XTENSION"); + char* xtension = getStringCopy("XTENSION"); char* simple = find("SIMPLE"); int r = (simple || (xtension && !strncmp(xtension, "IMAGE", 5))) && @@ -223,7 +223,7 @@ int FitsHead::isImage() int FitsHead::isTable() { - char* xtension = getString("XTENSION"); + char* xtension = getStringCopy("XTENSION"); int r = (xtension && (!strncmp(xtension, "TABLE", 5) || !strncmp(xtension, "BINTABLE", 8))); @@ -233,7 +233,7 @@ int FitsHead::isTable() int FitsHead::isAsciiTable() { - char* xtension = getString("XTENSION"); + char* xtension = getStringCopy("XTENSION"); int r = (xtension && (!strncmp(xtension, "TABLE", 5))); delete [] xtension; @@ -242,7 +242,7 @@ int FitsHead::isAsciiTable() int FitsHead::isBinTable() { - char* xtension = getString("XTENSION"); + char* xtension = getStringCopy("XTENSION"); int r = (xtension && (!strncmp(xtension, "BINTABLE", 8))); delete [] xtension; @@ -262,7 +262,7 @@ void FitsHead::updateHDU() // just find simple, it might be present but of value 'F' char* simple = find("SIMPLE"); - char* xtension = getString("XTENSION"); + char* xtension = getStringCopy("XTENSION"); if (xtension) inherit_ = getLogical("INHERIT",0); @@ -326,12 +326,12 @@ void FitsHead::getComplex(const char* name, double* real, double* img, } } -char* FitsHead::getString(const char* name) +char* FitsHead::getStringCopy(const char* name) { char* card = find(name); if (card) { FitsCard c(card); - return c.getString(); + return c.getStringCopy(); } else return NULL; diff --git a/tksao/fitsy++/head.h b/tksao/fitsy++/head.h index ad61a2a..cbc4b9d 100644 --- a/tksao/fitsy++/head.h +++ b/tksao/fitsy++/head.h @@ -121,7 +121,7 @@ public: double getReal(const char* name, double def); void getComplex(const char* name, double* real, double* img, double rdef, double idef); - char* getString(const char* name); + char* getStringCopy(const char* name); char* getComment(const char* name); char* getKeyword(const char* name); diff --git a/tksao/fitsy++/hist.C b/tksao/fitsy++/hist.C index 0c9f955..b6d6999 100644 --- a/tksao/fitsy++/hist.C +++ b/tksao/fitsy++/hist.C @@ -455,7 +455,7 @@ void FitsHist::mapWCSString(FitsHead* head, char* w, istr << prim << xcol_->index() << w << ends; if (head->find(istr.str().c_str())) { - char* cc = head->getString(istr.str().c_str()); + char* cc = head->getStringCopy(istr.str().c_str()); head_->appendString(out, cc, NULL); delete [] cc; } @@ -479,8 +479,8 @@ void FitsHist::mapWCSString(FitsHead* head, char* w, if (head->find(istr1.str().c_str()) || head->find(istr2.str().c_str())) { - char* cc1 = head->getString(istr1.str().c_str()); - char* cc2 = head->getString(istr2.str().c_str()); + char* cc1 = head->getStringCopy(istr1.str().c_str()); + char* cc2 = head->getStringCopy(istr2.str().c_str()); head_->appendString(ostr1.str().c_str(), cc1, NULL); head_->appendString(ostr2.str().c_str(), cc2, NULL); diff --git a/tksao/fitsy++/hpx.C b/tksao/fitsy++/hpx.C index 24b14ec..1695e36 100644 --- a/tksao/fitsy++/hpx.C +++ b/tksao/fitsy++/hpx.C @@ -432,7 +432,7 @@ void FitsHPX::initHeader(FitsFile* fits) head_ = new FitsHead(pWidth_, pHeight_, 1, -32); // OBJECT - char* object = src->getString("OBJECT"); + char* object = src->getStringCopy("OBJECT"); if (object) { head_->appendString("OBJECT", object, NULL); delete [] object; diff --git a/tksao/fitsy++/map.C b/tksao/fitsy++/map.C index 4984baa..355e09b 100644 --- a/tksao/fitsy++/map.C +++ b/tksao/fitsy++/map.C @@ -216,7 +216,7 @@ void FitsFitsMap::processRelax() // else, check for bin table with keyword PIXTYPE = 'HEALPIX ' if (head_->isBinTable() && head_->find("PIXTYPE") && - (!strncmp(head_->getString("PIXTYPE"),"HEALPIX",4))) { + (!strncmp(head_->getStringCopy("PIXTYPE"),"HEALPIX",4))) { found(here); return; } diff --git a/tksao/fitsy++/mapincr.C b/tksao/fitsy++/mapincr.C index be04c06..276c764 100644 --- a/tksao/fitsy++/mapincr.C +++ b/tksao/fitsy++/mapincr.C @@ -417,7 +417,7 @@ void FitsFitsMapIncr::processRelax() // else, check for bin table with keyword PIXTYPE = 'HEALPIX ' if (head_->isBinTable() && head_->find("PIXTYPE") && - (!strncmp(head_->getString("PIXTYPE"),"HEALPIX",4))) { + (!strncmp(head_->getStringCopy("PIXTYPE"),"HEALPIX",4))) { found(); return; } diff --git a/tksao/fitsy++/rice.C b/tksao/fitsy++/rice.C index 57df028..f7c8f3a 100644 --- a/tksao/fitsy++/rice.C +++ b/tksao/fitsy++/rice.C @@ -40,7 +40,7 @@ template FitsRicem::FitsRicem(FitsFile* fits) name[5] = '0'+ii; val[4] = '0'+ii; if (fits->find(name)) { - char* which = fits->getString(name); + char* which = fits->getStringCopy(name); if (!strncmp(which,"BLOCK",4)) block_ = fits->getInteger(val,32); else if (!strncmp(which,"BYTEPIX",4)) diff --git a/tksao/fitsy++/strm.C b/tksao/fitsy++/strm.C index 7be9e47..9876bbe 100644 --- a/tksao/fitsy++/strm.C +++ b/tksao/fitsy++/strm.C @@ -551,7 +551,7 @@ template void FitsFitsStream::processRelax() // else, check for bin table with keyword PIXTYPE = 'HEALPIX ' if (this->head_->isBinTable() && this->head_->find("PIXTYPE") && - (!strncmp(this->head_->getString("PIXTYPE"),"HEALPIX",4))) { + (!strncmp(this->head_->getStringCopy("PIXTYPE"),"HEALPIX",4))) { this->found(); return; } diff --git a/tksao/frame/fitscompress.C b/tksao/frame/fitscompress.C index d04c32f..e472490 100644 --- a/tksao/frame/fitscompress.C +++ b/tksao/frame/fitscompress.C @@ -12,7 +12,7 @@ void FitsImage::initCompress() { int bitpix = fits_->getInteger("ZBITPIX",0); - char* type = fits_->getString("ZCMPTYPE"); + char* type = fits_->getStringCopy("ZCMPTYPE"); if (!bitpix || !type) { if (type) delete [] type; diff --git a/tksao/frame/fitshealpix.C b/tksao/frame/fitshealpix.C index de8738e..4d0992b 100644 --- a/tksao/frame/fitshealpix.C +++ b/tksao/frame/fitshealpix.C @@ -25,7 +25,7 @@ void FitsImage::initHPX() if (fits_->pHPXSystem() >= 0) coord = (FitsHPX::CoordSys)fits_->pHPXSystem(); else { - char* str = head->getString("COORDSYS"); + char* str = head->getStringCopy("COORDSYS"); if (str) { if (str[0] == 'G') coord = FitsHPX::GAL; @@ -45,7 +45,7 @@ void FitsImage::initHPX() if (fits_->pHPXOrder() >=0) order = (FitsHPX::Order)fits_->pHPXOrder(); else { - char* str = head->getString("ORDERING"); + char* str = head->getStringCopy("ORDERING"); if (str) { if (str[0] == 'N') order = FitsHPX::NESTED; diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index a51e208..65a14be 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -898,7 +898,7 @@ void FitsImage::altWCS(istream& str) // Process OBJECT keyword if (objectKeyword_) delete [] objectKeyword_; - objectKeyword_ = hh->getString("OBJECT"); + objectKeyword_ = hh->getStringCopy("OBJECT"); // Process WCS keywords if (altHeader_) @@ -913,7 +913,7 @@ void FitsImage::appendWCS(istream& str) FitsHead* hh = parseWCS(str); // process OBJECT keyword - char* obj = hh->getString("OBJECT"); + char* obj = hh->getStringCopy("OBJECT"); if (obj) { if (objectKeyword_) delete [] objectKeyword_; @@ -1173,7 +1173,7 @@ void FitsImage::initWCS() #ifndef NEWWCS // WCSDEP if (hd->find("WCSDEP")) { - char* str = hd->getString("WCSDEP"); + char* str = hd->getStringCopy("WCSDEP"); if (str) { for (int ii=1; iifind("PIXTYPE") && (!strncmp(fits_->getString("PIXTYPE"),"HEALPIX",4))) || fits_->find("NSIDE")) { + else if ((fits_->find("PIXTYPE") && (!strncmp(fits_->getStringCopy("PIXTYPE"),"HEALPIX",4))) || fits_->find("NSIDE")) { initHPX(); if (!hpx_ || !hpx_->isValid()) { reset(); @@ -1997,11 +1997,11 @@ void FitsImage::processKeywordsPhysical() /* // Radio data? - char* bunit = image_->getString("BUNIT"); + char* bunit = image_->getStringCopy("BUNIT"); double cdelt1 = fabs(image_->getReal("CDELT1",0)); - char* cunit1 = image_->getString("CUNIT1"); + char* cunit1 = image_->getStringCopy("CUNIT1"); double cdelt2 = fabs(image_->getReal("CDELT2",0)); - char* cunit2 = image_->getString("CUNIT2"); + char* cunit2 = image_->getStringCopy("CUNIT2"); double bmaj = image_->getReal("BMAJ",0); double bmin = image_->getReal("BMIN",0); @@ -2031,7 +2031,7 @@ void FitsImage::processKeywordsParams() iparams.set(0, 0, width(), height()); { - char* datstr = image_->getString("DATASEC"); + char* datstr = image_->getStringCopy("DATASEC"); // default Vector v1(1,1); Vector v2(size()); @@ -2113,7 +2113,7 @@ int FitsImage::processKeywordsIRAF(FitsImage* fits) // DETSEC Coord::Orientation orientation = Coord::NORMAL; - char* detstr = image_->getString("DETSEC"); + char* detstr = image_->getStringCopy("DETSEC"); Vector dv1,dv2; if (!(detstr && *detstr && parseSection(detstr,&dv1,&dv2))) { if (detstr) @@ -2136,7 +2136,7 @@ int FitsImage::processKeywordsIRAF(FitsImage* fits) orientation = Coord::YY; // DETSIZE - char* sizestr = image_->getString("DETSIZE"); + char* sizestr = image_->getStringCopy("DETSIZE"); Vector sv1(1,1); Vector sv2(10000,10000); if (sizestr && *sizestr) { @@ -2151,7 +2151,7 @@ int FitsImage::processKeywordsIRAF(FitsImage* fits) // CCDSUM Vector ccdsum(1,1); - char* ccdstr = image_->getString("CCDSUM"); + char* ccdstr = image_->getStringCopy("CCDSUM"); if (ccdstr && *ccdstr) { double Ns, Np, Ns1, Np1; string x(ccdstr); @@ -2242,7 +2242,7 @@ void FitsImage::replaceWCS(istream& str) // Process OBJECT keyword if (objectKeyword_) delete [] objectKeyword_; - objectKeyword_ = hh->getString("OBJECT"); + objectKeyword_ = hh->getStringCopy("OBJECT"); // Process WCS keywords if (wcsHeader_) @@ -2302,7 +2302,7 @@ void FitsImage::resetWCS() // Process OBJECT keyword if (objectKeyword_) delete [] objectKeyword_; - objectKeyword_ = image_->getString("OBJECT"); + objectKeyword_ = image_->getStringCopy("OBJECT"); // Process WCS keywords if (wcsHeader_) @@ -3124,7 +3124,7 @@ const char* FitsImage::getWCSName(Coord::CoordSystem sys) return NULL; if (fits_->find("WCSNAME")) - return fits_->getString("WCSNAME"); + return fits_->getStringCopy("WCSNAME"); else return NULL; } @@ -3864,8 +3864,8 @@ void FitsImage::header2ast(int ii, FitsHead* hd, void* chan) if (!hd->find(key1) && !hd->find(key2)) return; - char* ctype1 = hd->getString(key1); - char* ctype2 = hd->getString(key2); + char* ctype1 = hd->getStringCopy(key1); + char* ctype2 = hd->getStringCopy(key2); if (ctype1 && !strncmp(ctype1,"GLON",4)) { if (!ctype2 || strncmp(ctype2,"GLAT",4)) { @@ -4144,19 +4144,19 @@ void FitsImage::wcs2ast(int ww, FitsHead* hd, FitsHead* prim, void* chan) radesys << "RADESYS" << alt << ends; if (hd->find(radesys.str().c_str())) { // if RADESYS present, use it - putFitsCard(chan, "RADESYS", hd->getString(radesys.str().c_str())); + putFitsCard(chan, "RADESYS", hd->getStringCopy(radesys.str().c_str())); } else if (prim && prim->find(radesys.str().c_str())) { // if RADESYS present, use it - putFitsCard(chan, "RADESYS", prim->getString(radesys.str().c_str())); + putFitsCard(chan, "RADESYS", prim->getStringCopy(radesys.str().c_str())); } else if (hd->find("RADECSYS")) { // look for old RADECSYS - putFitsCard(chan, "RADESYS", hd->getString("RADECSYS")); + putFitsCard(chan, "RADESYS", hd->getStringCopy("RADECSYS")); } else if (prim && prim->find("RADECSYS")) { // look for old RADECSYS - putFitsCard(chan, "RADESYS", prim->getString("RADECSYS")); + putFitsCard(chan, "RADESYS", prim->getStringCopy("RADECSYS")); } else { // fall back on wcssubs @@ -4232,14 +4232,14 @@ void FitsImage::wcs2ast(int ww, FitsHead* hd, FitsHead* prim, void* chan) ostringstream str; str << "WAT" << jj << "_00" << ii << ends; if (hd->find(str.str().c_str())) { - char* val = hd->getString(str.str().c_str()); + char* val = hd->getStringCopy(str.str().c_str()); if (val) { putFitsCard(chan, str.str().c_str(), val); delete [] val; } } else if (prim && prim->find(str.str().c_str())) { - char* val = prim->getString(str.str().c_str()); + char* val = prim->getStringCopy(str.str().c_str()); if (val) { putFitsCard(chan, str.str().c_str(), val); delete [] val; diff --git a/tksao/frame/frsave.C b/tksao/frame/frsave.C index 21406a5..332043b 100644 --- a/tksao/frame/frsave.C +++ b/tksao/frame/frsave.C @@ -377,34 +377,34 @@ void FrameBase::saveFitsResampleKeyword(OutFitsStream& str, FitsHead& dst) Vector center = Vector(options->width, options->height)/2.; // OBJECT - char* object = src->getString("OBJECT"); + char* object = src->getStringCopy("OBJECT"); if (object) { dst.appendString("OBJECT", object, NULL); delete [] object; } // DATE-OBS - char* date = src->getString("DATE"); + char* date = src->getStringCopy("DATE"); if (date) { dst.appendString("DATE", date, NULL); delete [] date; } - char* dateobs = src->getString("DATE-OBS"); + char* dateobs = src->getStringCopy("DATE-OBS"); if (dateobs) { dst.appendString("DATE-OBS", dateobs, NULL); delete [] dateobs; } - char* timeobs = src->getString("TIME-OBS"); + char* timeobs = src->getStringCopy("TIME-OBS"); if (timeobs) { dst.appendString("TIME-OBS", timeobs, NULL); delete [] timeobs; } - char* dateend = src->getString("DATE-END"); + char* dateend = src->getStringCopy("DATE-END"); if (dateend) { dst.appendString("DATE-END", dateend, NULL); delete [] dateend; } - char* timeend = src->getString("TIME-END"); + char* timeend = src->getStringCopy("TIME-END"); if (timeend) { dst.appendString("TIME-END", timeend, NULL); delete [] timeend; @@ -463,13 +463,13 @@ void FrameBase::saveFitsResampleKeyword(OutFitsStream& str, FitsHead& dst) dst.appendReal("CRVAL1", wcs->crval[0], 9, NULL); dst.appendReal("CRVAL2", wcs->crval[1], 9, NULL); - char* cunit1 = src->getString("CUNIT1"); + char* cunit1 = src->getStringCopy("CUNIT1"); if (cunit1) { dst.appendString("CUNIT1", cunit1, NULL); delete [] cunit1; } - char* cunit2 = src->getString("CUNIT2"); + char* cunit2 = src->getStringCopy("CUNIT2"); if (cunit2) { dst.appendString("CUNIT2", cunit2, NULL); delete [] cunit2; @@ -507,21 +507,21 @@ void FrameBase::saveFitsResampleKeyword(OutFitsStream& str, FitsHead& dst) #else if (src->find("RADESYS")) - dst.appendString("RADESYS", src->getString("RADESYS"), NULL); + dst.appendString("RADESYS", src->getStringCopy("RADESYS"), NULL); if (src->find("EQUINOX")) dst.appendReal("EQUINOX", src->getReal("EQUINOX",2000), 9, NULL); if (src->find("CTYPE1")) - dst.appendString("CTYPE1", src->getString("CTYPE1"), NULL); + dst.appendString("CTYPE1", src->getStringCopy("CTYPE1"), NULL); if (src->find("CTYPE2")) - dst.appendString("CTYPE2", src->getString("CTYPE2"), NULL); + dst.appendString("CTYPE2", src->getStringCopy("CTYPE2"), NULL); if (src->find("CRVAL1")) dst.appendReal("CRVAL1", src->getReal("CRVAL1",1), 9, NULL); if (src->find("CRVAL2")) dst.appendReal("CRVAL2", src->getReal("CRVAL2",1), 9, NULL); if (src->find("CUNIT1")) - dst.appendString("CUNIT1", src->getString("CUNIT1"), NULL); + dst.appendString("CUNIT1", src->getStringCopy("CUNIT1"), NULL); if (src->find("CUNIT2")) - dst.appendString("CUNIT2", src->getString("CUNIT2"), NULL); + dst.appendString("CUNIT2", src->getStringCopy("CUNIT2"), NULL); #endif } -- cgit v0.12