diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2017-10-04 18:07:27 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2017-10-04 18:07:27 (GMT) |
commit | 75c011ab3cea761212d11d5a15fe528fbbcdbcea (patch) | |
tree | bf18c1325bfab307f9ab4547896375994b44dfef /tksao | |
parent | 59aefd51a5c526b5d5e88cdc19cd6bf4b05995f4 (diff) | |
download | blt-75c011ab3cea761212d11d5a15fe528fbbcdbcea.zip blt-75c011ab3cea761212d11d5a15fe528fbbcdbcea.tar.gz blt-75c011ab3cea761212d11d5a15fe528fbbcdbcea.tar.bz2 |
track down memory leaks with getString
Diffstat (limited to 'tksao')
-rw-r--r-- | tksao/fitsy++/block.C | 4 | ||||
-rw-r--r-- | tksao/fitsy++/card.C | 3 | ||||
-rw-r--r-- | tksao/fitsy++/card.h | 2 | ||||
-rw-r--r-- | tksao/fitsy++/compress.C | 27 | ||||
-rw-r--r-- | tksao/fitsy++/hcompress.C | 5 | ||||
-rw-r--r-- | tksao/fitsy++/hdu.C | 6 | ||||
-rw-r--r-- | tksao/fitsy++/head.C | 20 | ||||
-rw-r--r-- | tksao/fitsy++/hist.C | 12 | ||||
-rw-r--r-- | tksao/fitsy++/hpx.C | 6 | ||||
-rw-r--r-- | tksao/fitsy++/map.C | 2 | ||||
-rw-r--r-- | tksao/fitsy++/mapincr.C | 2 | ||||
-rw-r--r-- | tksao/fitsy++/rice.C | 9 | ||||
-rw-r--r-- | tksao/fitsy++/strm.C | 2 |
13 files changed, 38 insertions, 62 deletions
diff --git a/tksao/fitsy++/block.C b/tksao/fitsy++/block.C index c8477ea..adf5f91 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_->getStringCopy("CCDSUM"); + char* val = head_->getString("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_->getStringCopy(key); + char* sec = head_->getString(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 57351ce..e10b807 100644 --- a/tksao/fitsy++/card.C +++ b/tksao/fitsy++/card.C @@ -4,6 +4,9 @@ #include "card.h" +// only used to return pointer to internal string +char FitsCard::buf_[FTY_CARDLEN]; + FitsCard::FitsCard() { card_ = new char[FTY_CARDLEN]; diff --git a/tksao/fitsy++/card.h b/tksao/fitsy++/card.h index c12265b..393ed8a 100644 --- a/tksao/fitsy++/card.h +++ b/tksao/fitsy++/card.h @@ -19,7 +19,7 @@ private: char* card_; int managed; // only used to return pointer to internal string - char buf_[FTY_CARDLEN]; + static char buf_[FTY_CARDLEN]; public: FitsCard(); diff --git a/tksao/fitsy++/compress.C b/tksao/fitsy++/compress.C index 3bc1bc9..425b4b1 100644 --- a/tksao/fitsy++/compress.C +++ b/tksao/fitsy++/compress.C @@ -28,16 +28,15 @@ FitsCompress::FitsCompress(FitsFile* fits) quantize_ = NODITHER; char keyword[] = "ZQUANTIZ"; if (fits->find(keyword)) { - char* which = fits->getStringCopy(keyword); - if (!strncmp(which,"NONE",4)) + char* str = fits->getString(keyword); + if (!strncmp(str,"NONE",4)) quantize_ = NONE; - if (!strncmp(which,"NO_DITHER",4)) + if (!strncmp(str,"NO_DITHER",4)) quantize_ = NODITHER; - else if (!strncmp(which,"SUBTRACTIVE_DITHER_1",20)) + else if (!strncmp(str,"SUBTRACTIVE_DITHER_1",20)) quantize_ = SUBDITHER1; - else if (!strncmp(which,"SUBTRACTIVE_DITHER_2",20)) + else if (!strncmp(str,"SUBTRACTIVE_DITHER_2",20)) quantize_ = SUBDITHER2; - delete [] which; } quantOffset_ = fits->getInteger("ZDITHER0",1); @@ -97,9 +96,8 @@ int FitsCompress::initHeader(FitsFile* fits) // FitsTableHDU* srcHDU = (FitsTableHDU*)(srcHead->hdu()); if (srcHead->find("ZTENSION")) { - char* str = srcHead->getStringCopy("ZTENSION"); + char* str = srcHead->getString("ZTENSION"); head_ = new FitsHead(width_, height_, depth_, bitpix_, str); - delete [] str; } else head_ = new FitsHead(width_, height_, depth_, bitpix_); @@ -153,13 +151,10 @@ int FitsCompress::initHeader(FitsFile* fits) // eat this one if (!strncmp(key,"EXTNAME",7)) { FitsCard cc(ptr); - char* str = cc.getStringCopy(); + char* str = cc.getString(); if (str) { - if (!strncmp(str,"COMPRESSED_IMAGE",8)) { - delete [] str; + if (!strncmp(str,"COMPRESSED_IMAGE",8)) continue; - } - delete [] str; } } @@ -182,19 +177,17 @@ int FitsCompress::initHeader(FitsFile* fits) } if (!strncmp(key,"ZHECKSUM",8)) { FitsCard cc(ptr); - char* str = cc.getStringCopy(); + char* str = cc.getString(); if (str) { head_->appendString("CHECKSUM",str,NULL); - delete [] str; continue; } } if (!strncmp(key,"ZDATASUM",8)) { FitsCard cc(ptr); - char* str = cc.getStringCopy(); + char* str = cc.getString(); if (str) { head_->appendString("DATASUM",str,NULL); - delete [] str; continue; } } diff --git a/tksao/fitsy++/hcompress.C b/tksao/fitsy++/hcompress.C index 4a55398..45580db 100644 --- a/tksao/fitsy++/hcompress.C +++ b/tksao/fitsy++/hcompress.C @@ -30,10 +30,9 @@ template<class T> FitsHcompressm<T>::FitsHcompressm(FitsFile* fits) name[5] = '0'+ii; val[4] = '0'+ii; if (fits->find(name)) { - char* which = fits->getStringCopy(name); - if (!strncmp(which,"SMOOTH",4)) + char* str = fits->getString(name); + if (!strncmp(str,"SMOOTH",4)) smooth_ = fits->getInteger(val,4); - delete [] which; } } diff --git a/tksao/fitsy++/hdu.C b/tksao/fitsy++/hdu.C index 2c15e14..7a1715b 100644 --- a/tksao/fitsy++/hdu.C +++ b/tksao/fitsy++/hdu.C @@ -210,7 +210,7 @@ FitsAsciiTableHDU::FitsAsciiTableHDU(FitsHead* head) : FitsTableHDU(head) size_t offset = 0; for (int i=0; i<tfields_; i++) { - char* tform = head->getStringCopy(keycat("TFORM",i+1)); + char* tform = head->getString(keycat("TFORM",i+1)); char type = 'F'; if (tform) { string x(tform); @@ -236,7 +236,6 @@ FitsAsciiTableHDU::FitsAsciiTableHDU(FitsHead* head) : FitsTableHDU(head) break; } - delete [] tform; if (cols_[i]) offset += cols_[i]->width(); } @@ -248,7 +247,7 @@ FitsBinTableHDU::FitsBinTableHDU(FitsHead* head) : FitsTableHDU(head) int offset =0; for (int i=0; i<tfields_; i++) { - char* tform = head->getStringCopy(keycat("TFORM",i+1)); + char* tform = head->getString(keycat("TFORM",i+1)); int repeat; char type = 'J'; if (tform) { @@ -315,7 +314,6 @@ FitsBinTableHDU::FitsBinTableHDU(FitsHead* head) : FitsTableHDU(head) break; } - delete [] tform; if (cols_[i]) offset += cols_[i]->width(); } diff --git a/tksao/fitsy++/head.C b/tksao/fitsy++/head.C index 75f5749..e6722db 100644 --- a/tksao/fitsy++/head.C +++ b/tksao/fitsy++/head.C @@ -209,43 +209,35 @@ FitsHead::~FitsHead() int FitsHead::isImage() { // just look for SIMPLE, if present it may be of value 'F' - char* xtension = getStringCopy("XTENSION"); + char* xtension = getString("XTENSION"); char* simple = find("SIMPLE"); int r = (simple || (xtension && !strncmp(xtension, "IMAGE", 5))) && naxes() > 0 && naxis(0) > 0 && naxis(1) > 0; - - delete [] xtension; return r; } int FitsHead::isTable() { - char* xtension = getStringCopy("XTENSION"); + char* xtension = getString("XTENSION"); int r = (xtension && (!strncmp(xtension, "TABLE", 5) || !strncmp(xtension, "BINTABLE", 8))); - - delete [] xtension; return r; } int FitsHead::isAsciiTable() { - char* xtension = getStringCopy("XTENSION"); + char* xtension = getString("XTENSION"); int r = (xtension && (!strncmp(xtension, "TABLE", 5))); - - delete [] xtension; return r; } int FitsHead::isBinTable() { - char* xtension = getStringCopy("XTENSION"); + char* xtension = getString("XTENSION"); int r = (xtension && (!strncmp(xtension, "BINTABLE", 8))); - - delete [] xtension; return r; } @@ -262,7 +254,7 @@ void FitsHead::updateHDU() // just find simple, it might be present but of value 'F' char* simple = find("SIMPLE"); - char* xtension = getStringCopy("XTENSION"); + char* xtension = getString("XTENSION"); if (xtension) inherit_ = getLogical("INHERIT",0); @@ -275,8 +267,6 @@ void FitsHead::updateHDU() if (xtension && !strncmp(xtension, "BINTABLE", 8)) hdu_ = new FitsBinTableHDU(this); - - delete [] xtension; } int FitsHead::getLogical(const char* name, int def) diff --git a/tksao/fitsy++/hist.C b/tksao/fitsy++/hist.C index b6d6999..b8655e0 100644 --- a/tksao/fitsy++/hist.C +++ b/tksao/fitsy++/hist.C @@ -455,9 +455,8 @@ void FitsHist::mapWCSString(FitsHead* head, char* w, istr << prim << xcol_->index() << w << ends; if (head->find(istr.str().c_str())) { - char* cc = head->getStringCopy(istr.str().c_str()); - head_->appendString(out, cc, NULL); - delete [] cc; + char* str = head->getString(istr.str().c_str()); + head_->appendString(out, str, NULL); } } @@ -479,13 +478,10 @@ void FitsHist::mapWCSString(FitsHead* head, char* w, if (head->find(istr1.str().c_str()) || head->find(istr2.str().c_str())) { - char* cc1 = head->getStringCopy(istr1.str().c_str()); - char* cc2 = head->getStringCopy(istr2.str().c_str()); - + char* cc1 = head->getString(istr1.str().c_str()); head_->appendString(ostr1.str().c_str(), cc1, NULL); + char* cc2 = head->getString(istr2.str().c_str()); head_->appendString(ostr2.str().c_str(), cc2, NULL); - delete [] cc1; - delete [] cc2; } } diff --git a/tksao/fitsy++/hpx.C b/tksao/fitsy++/hpx.C index 1695e36..a95b6c3 100644 --- a/tksao/fitsy++/hpx.C +++ b/tksao/fitsy++/hpx.C @@ -432,11 +432,9 @@ void FitsHPX::initHeader(FitsFile* fits) head_ = new FitsHead(pWidth_, pHeight_, 1, -32); // OBJECT - char* object = src->getStringCopy("OBJECT"); - if (object) { + char* object = src->getString("OBJECT"); + if (object) head_->appendString("OBJECT", object, NULL); - delete [] object; - } // CRPIX1/2 float crpix1; diff --git a/tksao/fitsy++/map.C b/tksao/fitsy++/map.C index 355e09b..4984baa 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_->getStringCopy("PIXTYPE"),"HEALPIX",4))) { + (!strncmp(head_->getString("PIXTYPE"),"HEALPIX",4))) { found(here); return; } diff --git a/tksao/fitsy++/mapincr.C b/tksao/fitsy++/mapincr.C index 276c764..be04c06 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_->getStringCopy("PIXTYPE"),"HEALPIX",4))) { + (!strncmp(head_->getString("PIXTYPE"),"HEALPIX",4))) { found(); return; } diff --git a/tksao/fitsy++/rice.C b/tksao/fitsy++/rice.C index f7c8f3a..02f9a7f 100644 --- a/tksao/fitsy++/rice.C +++ b/tksao/fitsy++/rice.C @@ -40,14 +40,13 @@ template<class T> FitsRicem<T>::FitsRicem(FitsFile* fits) name[5] = '0'+ii; val[4] = '0'+ii; if (fits->find(name)) { - char* which = fits->getStringCopy(name); - if (!strncmp(which,"BLOCK",4)) + char* str = fits->getString(name); + if (!strncmp(str,"BLOCK",4)) block_ = fits->getInteger(val,32); - else if (!strncmp(which,"BYTEPIX",4)) + else if (!strncmp(str,"BYTEPIX",4)) bytepix_ = fits->getInteger(val,4); - else if (!strncmp(which,"NOISEBIT",4)) + else if (!strncmp(str,"NOISEBIT",4)) noisebit_ = fits->getInteger(val,4); - delete [] which; } } diff --git a/tksao/fitsy++/strm.C b/tksao/fitsy++/strm.C index 9876bbe..7be9e47 100644 --- a/tksao/fitsy++/strm.C +++ b/tksao/fitsy++/strm.C @@ -551,7 +551,7 @@ template<class T> void FitsFitsStream<T>::processRelax() // else, check for bin table with keyword PIXTYPE = 'HEALPIX ' if (this->head_->isBinTable() && this->head_->find("PIXTYPE") && - (!strncmp(this->head_->getStringCopy("PIXTYPE"),"HEALPIX",4))) { + (!strncmp(this->head_->getString("PIXTYPE"),"HEALPIX",4))) { this->found(); return; } |