Comments (6)
Ok, accepted. Await another PR soon :)
from collections-c.
Awesome :)
from collections-c.
I don't think it's much of a problem since the user would have to pass an out
to slist_iter_next
anyway and would thus have a reference to free.
...
void *e;
while (slist_iter_next(iter, &e) != CC_ITER_END) {
...
slist_iter_remove(iter, NULL); // Even though the output is ignored the user still has
// access to the removed reference within the iterator context
}
Basically iter_remove
removes the element that was already returned by the iter_next
and it can't operate on any other value so it should be safe to ignore its out
parameter.
from collections-c.
Maybe I'm missing something... but it seems to me that the caller cannot access the data of the removed element due to these lines:
void *e = unlink(iter->list, iter->current, iter->prev);
iter->current = NULL;
The only option to store the pointer to data is to provide 'out'.
from collections-c.
Basically, I started digging into this because valgrind is reporting memory leaks when running 'slist_test'. Some of them are internal to the test code, but others lead to the functions like slist_iter_remove
.
from collections-c.
Technically true because after you call iter_remove
you can no longer access the data from the list, but in practice iter_next
gives you the data pointer before you get a chance to remove it from the list. iter_remove
's out
just returns the same thing that iter_next
out returned and that's why it's not really a big deal if you ignore it or not.
I also ran valgrind and it seems that the problems are actually coming from slist_1234
, or to be more precise not freeing its malloced data properly. Usually this list is freed by calling slist_destroy_free
which also calls free
on the data (and sometimes it's not freed at all :-), but since some of the malloced values are removed from the list, slist_destroy_free
can't reach them. This is why the problem mostly comes from tests that call remove
.
This can be fixed by manualy freeing the data after the remove:
int *e;
while (slist_iter_next(&iter, (void*) &e) != CC_ITER_END) {
if (*e == 3) {
slist_iter_remove(&iter, NULL);
free(e); // don't let data float around in interdimensional space
}
}
from collections-c.
Related Issues (20)
- Problem in hashtable HOT 1
- Adding a Ternary Search Tree HOT 1
- is a Vector data structure available? HOT 7
- rbuf_conf_new test
- How about adding AVL or Red Black tree data structure? HOT 4
- (deque.c): inline function upper_pow_two only valid for 32 bit size_t HOT 5
- PQueue heap-overflow HOT 1
- deque_remove_at error
- cc_array_reverse() fails when element count is even HOT 1
- Implementation error in `cc_array_reverse` and `cc_deque_reverse`
- cmake configuration failed on latest MSYS2 HOT 1
- document is inaccurate about key_compare function
- Is "stdio.h" necessary? HOT 1
- The call to mem_alloc in cc_array_subarray() is unsafe
- How about adding Bloom Filter data structure? HOT 2
- cc_list.c (index > list1->size)maybe is wrong
- file: cc_list.c function:static INLINE void merge(……) HOT 1
- File: cc_list.c Function: cc_list_iter_add
- Feature Request: provide release versioning HOT 1
- RFC: Distro specific packages HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collections-c.