wangxiaowei0303 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Segmentation fault with CrtAllocator #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use CrtAllocator instead of MemoryPoolAllocator.
2. Add values to objects or arrays.

What is the expected output? What do you see instead?
It should add values normally.
But sometimes segmentation fault occur.

The problem exists in the AddMember() and PushBack() methods of GenericValue.
They allocate memory and then assign new values into that memory.
This assignment is overloaded and calls the destructor on uninitialized data 
before copying the new values.
The destructor checks if kNeedFree is true and then tries to determine the 
specific type of the value and if it has to free more memory recursively.

There is no problem with MemoryPoolAllocator because it has kNeedFree on false 
and so the destructor has nothing to do.

I think the assignment operators in AddMember() and PushBack() should replaced 
by RawAssign() method which doesn't call the destructor.

I added a patch file.

Original issue reported on code.google.com by ackder...@gmail.com on 30 Sep 2012 at 6:21

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r80.

Original comment by milo...@gmail.com on 14 Nov 2012 at 3:33

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r81.

Original comment by milo...@gmail.com on 14 Nov 2012 at 3:35

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 4ee17e67b1a4.

Original comment by milo...@gmail.com on 6 Jun 2014 at 6:04