Commit 01793fce authored by Marcin Kolny's avatar Marcin Kolny

Gst::Iterator: fix memory leak

parent c5006faf
......@@ -116,7 +116,7 @@ protected:
IteratorBase<CppType>& operator=(const IteratorBase<CppType>& other);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
GValue* current; // The current element the iterator is referencing.
GValue current; // The current element the iterator is referencing.
IteratorResult current_result; // The current result of a next() call.
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
......@@ -241,7 +241,7 @@ public:
template<class CppType>
IteratorBase<CppType>::IteratorBase()
: current(new GValue()),
: current(G_VALUE_INIT),
current_result(Gst::ITERATOR_OK),
cobject_(0),
take_ownership(true)
......@@ -258,7 +258,7 @@ IteratorBase<CppType>::IteratorBase(const IteratorBase<CppType>& other)
template<class CppType>
IteratorBase<CppType>::IteratorBase(GstIterator* castitem, bool take_ownership)
: current(new GValue()),
: current(G_VALUE_INIT),
current_result(Gst::ITERATOR_OK),
cobject_(castitem),
take_ownership(take_ownership)
......@@ -276,15 +276,15 @@ template<class CppType>
IteratorResult IteratorBase<CppType>::next()
{
// Unset current before calling gst_iterator_next()
if(G_IS_VALUE(this->current))
g_value_unset(this->current);
if(G_IS_VALUE(&current))
g_value_unset(&current);
current_result =
static_cast<Gst::IteratorResult>(gst_iterator_next(cobj(), current));
static_cast<Gst::IteratorResult>(gst_iterator_next(cobj(), &current));
// Reset current if iterator is done:
if(current_result == Gst::ITERATOR_DONE)
g_value_reset (current);
g_value_reset (&current);
return current_result;
}
......@@ -293,14 +293,14 @@ template<class CppType>
void IteratorBase<CppType>::resync()
{
gst_iterator_resync(cobj());
g_value_reset (current);
g_value_reset (&current);
current_result = Gst::ITERATOR_OK;
}
template<class CppType>
bool IteratorBase<CppType>::is_start() const
{
return (G_VALUE_HOLDS_OBJECT(current) && current_result == Gst::ITERATOR_OK);
return (G_VALUE_HOLDS_OBJECT(&current) && current_result == Gst::ITERATOR_OK);
}
template<class CppType>
......@@ -312,7 +312,7 @@ bool IteratorBase<CppType>::is_end() const
template<class CppType>
IteratorBase<CppType>::operator bool() const
{
return (! G_VALUE_HOLDS_OBJECT(current));
return (! G_VALUE_HOLDS_OBJECT(&current));
}
template<class CppType>
......@@ -328,8 +328,8 @@ void IteratorBase<CppType>::swap(IteratorBase<CppType>& other)
GValue temp_current = G_VALUE_INIT;
g_value_init(&temp_current, G_VALUE_TYPE(current));
g_value_copy(current, &temp_current);
g_value_copy(other.current, current);
g_value_copy(&current, &temp_current);
g_value_copy(other.current, &current);
g_value_copy(&temp_current, other.current);
const IteratorResult temp_result = current_result;
......@@ -346,8 +346,8 @@ IteratorBase<CppType>::~IteratorBase()
gst_iterator_free(cobject_);
cobject_ = nullptr;
}
if(G_IS_VALUE(this->current))
g_value_unset(this->current);
if(G_IS_VALUE(&current))
g_value_unset(&current);
}
/***************** Gst::IteratorBasic<CppType> ***********************/
......@@ -375,8 +375,8 @@ CppType IteratorBasic<CppType>::operator*() const
{
typedef typename CppType::BaseObjectType CType;
if(G_IS_VALUE(this->current))
return CppType(static_cast<CType*>(g_value_get_object(this->current)));
if(G_IS_VALUE(&this->current))
return CppType(static_cast<CType*>(g_value_get_object(&this->current)));
else
return CppType();
}
......@@ -386,7 +386,7 @@ CppType* IteratorBasic<CppType>::operator->() const
{
static typename CppType::CppObjectType result;
if(G_IS_VALUE(this->current))
if(G_IS_VALUE(&this->current))
{
result = this->operator*();
return &result;
......@@ -442,11 +442,11 @@ Glib::RefPtr<CppType> Iterator<CppType>::operator*() const
{
typedef typename CppType::BaseObjectType CType;
if(G_IS_VALUE(this->current))
if(G_IS_VALUE(&this->current))
{
//Take extra reference when dereferencing. The reference will disappear
//when Glib::RefPtr<> is destroyed.
return Glib::wrap(static_cast<CType*>(g_value_get_object (this->current)), true);
return Glib::wrap(static_cast<CType*>(g_value_get_object (&this->current)), true);
}
else
return Glib::RefPtr<CppType>(0);
......@@ -457,11 +457,11 @@ CppType* Iterator<CppType>::operator->() const
{
typedef typename CppType::BaseObjectType CType;
if(G_IS_VALUE(this->current))
if(G_IS_VALUE(&this->current))
{
//Take extra reference when dereferencing. The reference will disappear
//when Glib::RefPtr<> is destroyed.
return Glib::wrap(static_cast<CType*>(g_value_get_object (this->current)), true).operator->();
return Glib::wrap(static_cast<CType*>(g_value_get_object (&this->current)), true).operator->();
}
else
return static_cast<CppType*>(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment