diff options
author | Darryl L. Pierce <mcpierce@apache.org> | 2013-03-18 19:15:17 +0000 |
---|---|---|
committer | Darryl L. Pierce <mcpierce@apache.org> | 2013-03-18 19:15:17 +0000 |
commit | 84c34805896806982d1d2c232fd197b17b0d909a (patch) | |
tree | 48bec9865111aedbae79f22f8b2a738493decb0b | |
parent | a1a2ba2cf8663e3b4cade0e5f439e03f1e5da76b (diff) | |
download | qpid-python-84c34805896806982d1d2c232fd197b17b0d909a.tar.gz |
QPID-4493: Fixes memory leak in Perl bindings.
Contributed by: Jimmy Jones <jimmyjones2@gmx.co.uk>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1457923 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/bindings/qpid/perl/t/Message.t | 7 | ||||
-rw-r--r-- | qpid/cpp/include/qpid/swig_perl_typemaps.i | 33 |
2 files changed, 25 insertions, 15 deletions
diff --git a/qpid/cpp/bindings/qpid/perl/t/Message.t b/qpid/cpp/bindings/qpid/perl/t/Message.t index 15baafb446..c656a7cf90 100644 --- a/qpid/cpp/bindings/qpid/perl/t/Message.t +++ b/qpid/cpp/bindings/qpid/perl/t/Message.t @@ -265,6 +265,13 @@ $map = qpid::messaging::decode_map($message); ok ($map->{name} eq "Euro=\x{20AC}", "Unicode strings encoded correctly."); +# Maps inside maps should work +$content = { id => 1234, name => { first => "tom" } }; +qpid::messaging::encode($content, $message); +$map = qpid::messaging::decode_map($message); +ok ($map->{name}{first} eq "tom", + "Map inside map encoded correctly."); + # Setting the content as a hash automatically encodes it ($content) = {"id" => "1234", "name" => "qpid"}; $message->set_content($content); diff --git a/qpid/cpp/include/qpid/swig_perl_typemaps.i b/qpid/cpp/include/qpid/swig_perl_typemaps.i index 7730b69ce7..c1e1d53d94 100644 --- a/qpid/cpp/include/qpid/swig_perl_typemaps.i +++ b/qpid/cpp/include/qpid/swig_perl_typemaps.i @@ -60,11 +60,11 @@ } SV* VariantToPerl(const qpid::types::Variant* v) { - SV* result = newSV(0); + SV* result = 0; try { switch (v->getType()) { case qpid::types::VAR_VOID: { - sv_setiv(result, (IV)0); + result = newSViv(0); break; } case qpid::types::VAR_BOOL : { @@ -74,29 +74,29 @@ case qpid::types::VAR_UINT8 : case qpid::types::VAR_UINT16 : case qpid::types::VAR_UINT32 : { - sv_setuv(result, (UV)v->asUint32()); + result = newSVuv((UV)v->asUint32()); break; } case qpid::types::VAR_UINT64 : { - sv_setuv(result, (UV)v->asUint64()); + result = newSVuv((UV)v->asUint64()); break; } case qpid::types::VAR_INT8 : case qpid::types::VAR_INT16 : case qpid::types::VAR_INT32 : { - sv_setiv(result, (IV)v->asInt32()); + result = newSViv((IV)v->asInt32()); break; } case qpid::types::VAR_INT64 : { - sv_setiv(result, (IV)v->asInt64()); + result = newSViv((IV)v->asInt64()); break; } case qpid::types::VAR_FLOAT : { - sv_setnv(result, (double)v->asFloat()); + result = newSVnv((double)v->asFloat()); break; } case qpid::types::VAR_DOUBLE : { - sv_setnv(result, (double)v->asDouble()); + result = newSVnv((double)v->asDouble()); break; } case qpid::types::VAR_STRING : { @@ -122,6 +122,9 @@ Perl_croak(aTHX_ ex.what()); } + if (!result) + result = newSV(0); + return result; } @@ -133,7 +136,7 @@ SV* perlval = VariantToPerl(&(iter->second)); hv_store(hv, key.c_str(), key.size(), perlval, 0); } - return sv_2mortal(newRV_noinc((SV *)hv)); + return newRV_noinc((SV *)hv); } SV* ListToPerl(const qpid::types::Variant::List* list) { @@ -143,7 +146,7 @@ SV* perlval = VariantToPerl(&(*iter)); av_push(av, perlval); } - return sv_2mortal(newRV_noinc((SV *)av)); + return newRV_noinc((SV *)av); } void PerlToMap(SV* hash, qpid::types::Variant::Map* map) { @@ -229,27 +232,27 @@ * Variant types: C++ --> Perl */ %typemap(out) qpid::types::Variant::Map { - $result = MapToPerl(&$1); + $result = sv_2mortal(MapToPerl(&$1)); argvi++; } %typemap(out) qpid::types::Variant::Map& { - $result = MapToPerl($1); + $result = sv_2mortal(MapToPerl($1)); argvi++; } %typemap(out) qpid::types::Variant::List { - $result = ListToPerl(&$1); + $result = sv_2mortal(ListToPerl(&$1)); argvi++; } %typemap(out) qpid::types::Variant::List& { - $result = ListToPerl($1); + $result = sv_2mortal(ListToPerl($1)); argvi++; } %typemap(out) qpid::types::Variant& { - $result = VariantToPerl($1); + $result = sv_2mortal(VariantToPerl($1)); argvi++; } |