4 ms·
> There doesn't look like there's actually anything preventing the user from calling free themselves True, but wouldn't that still be memory safe? It seems to
by tgv 3y ago
> There doesn't look like there's actually anything preventing the user from calling free themselves
True, but wouldn't that still be memory safe? It seems to me that it could lead to a memory leak, but not to double use of memory. But another annotation to the type so that free() can only be called at one point (or perhaps a few points) might solve that.
- dwattttt 3y agoAn adversary can turn a double free into a use after free by causing an object to be allocated in-between the two free operations at the same address
- tgv 3y agoYou can't free a buffer/object twice in the proposal. After a free, you can't use the pointer any longer. But it might very well be that this approach is not hard enough for use in e.g. the kernel. It might still be useful for userland applications, though.
- chc4 3y agoIt doesn't leak memory, but the example use case of "high RAII" isn't about not leaking memory but that "the compiler can ensure you remember to do something in the future and don't accidentally forget it" and "remember to remove something from a cache that you previously added to" - which isn't actually done, because the consumer can call free and the data will still erroneously be in a cache, for example.