0ct0cat / spexamples

Automatically exported from code.google.com/p/spexamples
0 stars 0 forks source link

动态数组内存管理的两个问题 #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.1.darray_set_by_index

2.1.get_by_index(thiz, 1, &pdata)
2.2.set_by_index(thiz, 2, pdata)
2.3.darray_destroy(thiz)

What is the expected output? What do you see instead?
1.直接set而不去free原有的元素,导致原有的元素所指向的内��
�不再有指针来标记,从而无法释放造成内存泄漏。

2.此条为疑问。这样操作会造成index 
1和2都指向同一块内存,在destroy的时候这块内存会被free两次�
��会不会出现什么问题?这个问题如果往下引申的话若数组中
有两个元素的指针指向同一块内存,其中一个元素被free之后�
��另一个指针的性质岂不是和野指针一样?这种情况下内存应
该如何管理呢?

What version of the product are you using? On what operating system?
Last Changed Rev: 5
Last Changed Date: 2010-04-21 21:37:48 +0800 (Wed, 21 Apr 2010)

ubuntu

Please provide any additional information below.

Original issue reported on code.google.com by crystalh...@gmail.com on 28 Mar 2011 at 3:17