diff options
author | David Tardon <dtardon@redhat.com> | 2011-05-16 15:28:20 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2011-05-16 15:28:20 +0200 |
commit | d971198fd36f40455e098078159b130bafc6116c (patch) | |
tree | 598e96f7dbe67a576f29f0c5e41c05194bebd5a1 /hwpfilter | |
parent | do not leak memory (diff) | |
download | core-d971198fd36f40455e098078159b130bafc6116c.tar.gz core-d971198fd36f40455e098078159b130bafc6116c.zip |
do not leak memory
Diffstat (limited to 'hwpfilter')
-rw-r--r-- | hwpfilter/source/hwpreader.cxx | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index ff45aa031b72..f559ae0ea17e 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -29,6 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_hwpfilter.hxx" +#include <boost/shared_ptr.hpp> + #include "hwpreader.hxx" #include <math.h> //#ifndef UDK100 @@ -84,6 +86,20 @@ static hchar sbuf[256]; static hchar *field = 0L; static char buf[1024]; +namespace +{ + +template<typename T> +struct Free +{ + void operator()(T* const ptr) + { + free(ptr); + } +}; + +} + struct HwpReaderPrivate { HwpReaderPrivate() @@ -1781,7 +1797,8 @@ void HwpReader::makePageStyle() if( hwpinfo->back_info.type == 2 ){ rstartEl(ascii("office:binary-data"), rList); pList->clear(); - rchars(ascii(base64_encode_string((unsigned char *) hwpinfo->back_info.data, hwpinfo->back_info.size ))); + boost::shared_ptr<char> pStr(base64_encode_string((unsigned char *) hwpinfo->back_info.data, hwpinfo->back_info.size ), Free<char>()); + rchars(ascii(pStr.get())); rendEl(ascii("office:binary-data")); } rendEl(ascii("style:background-image")); @@ -3993,7 +4010,10 @@ void HwpReader::makePicture(Picture * hbox) if( hbox->pictype == PICTYPE_EMBED ){ EmPicture *emp = hwpfile.GetEmPicture(hbox); if( emp ) - rchars(ascii(base64_encode_string( emp->data, emp->size ))); + { + boost::shared_ptr<char> pStr(base64_encode_string( emp->data, emp->size ), Free<char>()); + rchars(ascii(pStr.get())); + } } else{ if( hwpfile.oledata ){ @@ -4015,7 +4035,8 @@ void HwpReader::makePicture(Picture * hbox) rchars(ascii("")); } else{ - rchars(ascii(base64_encode_string( (uchar *)pObj, strlen((char *)pObj) ))); + boost::shared_ptr<char> pStr(base64_encode_string( (uchar *)pObj, strlen((char *)pObj)), Free<char>()); + rchars(ascii(pStr.get())); pObj->Release(); srcsto->Release(); } |