Remix.run Logo
SkiFire13 3 days ago

The difference is that memory won't do anything under your nose, it can't run arbitrary code by itself. It won't spawn threads, create thread locals, or store data in global variables. And it's normal to track the lifetime of memory, much less the lifetime of code and function pointers passed around.

immibis 3 days ago | parent | next [-]

The same is true of DLLs. They don't do anything by themselves; they are merely blocks of bytes mapped into memory.

Why is tracking the lifetime of a function pointer different from tracking the lifetime of any other pointer?

FreeLibrary on Windows unloads libraries when the reference count is zero.

SkiFire13 15 hours ago | parent [-]

> The same is true of DLLs. They don't do anything by themselves; they are merely blocks of bytes mapped into memory.

FYI just loading a DLL can execute code.

> Why is tracking the lifetime of a function pointer different from tracking the lifetime of any other pointer?

Technically speaking none, but historically this is something that nobody did, so we are full of code that assumes function pointers to have a static lifetime. It's a social problem.

AstralStorm 2 days ago | parent | prev [-]

You could do that, but then you're running valgrind.