msvcirt: Fix leak in ~ios and ios::init implementation.

This commit is contained in:
Piotr Caban 2015-07-08 10:28:59 +02:00 committed by Alexandre Julliard
parent 849bb99b76
commit 4406762dc2
2 changed files with 9 additions and 5 deletions

View File

@ -172,6 +172,8 @@ streambuf* __thiscall streambuf_assign(streambuf *this, const streambuf *rhs)
/* ??_Estreambuf@@UAEPAXI@Z */ /* ??_Estreambuf@@UAEPAXI@Z */
DEFINE_THISCALL_WRAPPER(streambuf_vector_dtor, 8) DEFINE_THISCALL_WRAPPER(streambuf_vector_dtor, 8)
#define call_streambuf_vector_dtor(this, flags) CALL_VTBL_FUNC(this, 0,\
streambuf*, (streambuf*, unsigned int), (this, flags))
streambuf* __thiscall streambuf_vector_dtor(streambuf *this, unsigned int flags) streambuf* __thiscall streambuf_vector_dtor(streambuf *this, unsigned int flags)
{ {
TRACE("(%p %x)\n", this, flags); TRACE("(%p %x)\n", this, flags);
@ -753,7 +755,7 @@ void __thiscall ios_dtor(ios *this)
{ {
TRACE("(%p)\n", this); TRACE("(%p)\n", this);
if (this->delbuf && this->sb) if (this->delbuf && this->sb)
MSVCRT_operator_delete(this->sb); call_streambuf_vector_dtor(this->sb, 1);
this->sb = NULL; this->sb = NULL;
this->state = IOSTATE_badbit; this->state = IOSTATE_badbit;
DeleteCriticalSection(&this->lock); DeleteCriticalSection(&this->lock);
@ -958,7 +960,7 @@ void __thiscall ios_init(ios *this, streambuf *sb)
{ {
TRACE("(%p %p)\n", this, sb); TRACE("(%p %p)\n", this, sb);
if (this->delbuf && this->sb) if (this->delbuf && this->sb)
MSVCRT_operator_delete(this->sb); call_streambuf_vector_dtor(this->sb, 1);
this->sb = sb; this->sb = sb;
if (sb == NULL) if (sb == NULL)
this->state |= IOSTATE_badbit; this->state |= IOSTATE_badbit;

View File

@ -813,7 +813,7 @@ static void test_ios(void)
memset(&ios_obj, 0xab, sizeof(ios)); memset(&ios_obj, 0xab, sizeof(ios));
memset(&ios_obj2, 0xab, sizeof(ios)); memset(&ios_obj2, 0xab, sizeof(ios));
psb = p_operator_new(sizeof(streambuf)); psb = p_operator_new(sizeof(streambuf));
if (psb) ok(psb != NULL, "failed to allocate streambuf object\n");
call_func1(p_streambuf_ctor, psb); call_func1(p_streambuf_ctor, psb);
/* constructor/destructor */ /* constructor/destructor */
@ -857,10 +857,12 @@ static void test_ios(void)
ok(ios_obj.sb == NULL, "expected %p got %p\n", NULL, ios_obj.sb); ok(ios_obj.sb == NULL, "expected %p got %p\n", NULL, ios_obj.sb);
ok(ios_obj.state == (0x8|IOSTATE_badbit), "expected %x got %x\n", (0x8|IOSTATE_badbit), ios_obj.state); ok(ios_obj.state == (0x8|IOSTATE_badbit), "expected %x got %x\n", (0x8|IOSTATE_badbit), ios_obj.state);
ios_obj.sb = psb; ios_obj.sb = psb;
ios_obj.delbuf = 1; ios_obj.delbuf = 0;
call_func2(p_ios_init, &ios_obj, psb); call_func2(p_ios_init, &ios_obj, psb);
ok(ios_obj.sb == psb, "expected %p got %p\n", psb, ios_obj.sb); ok(ios_obj.sb == psb, "expected %p got %p\n", psb, ios_obj.sb);
ok(ios_obj.state == 0x8, "expected %x got %x\n", 0x8, ios_obj.state); ok(ios_obj.state == 0x8, "expected %x got %x\n", 0x8, ios_obj.state);
ios_obj.delbuf = 1;
call_func1(p_ios_dtor, &ios_obj);
/* copy constructor */ /* copy constructor */
call_func2(p_ios_copy_ctor, &ios_obj, &ios_obj2); call_func2(p_ios_copy_ctor, &ios_obj, &ios_obj2);