dlang-community / d2sqlite3

A small wrapper around SQLite for the D programming language
Boost Software License 1.0
75 stars 26 forks source link

No creating exceptions in a destructor #31

Closed cyisfor closed 8 years ago

cyisfor commented 8 years ago

In Database.~this() the destructor allocates memory, which causes any program to crash, if the database is destroyed during a garbage collection.

Garbage collection dies badly if you ever allocate memory via GC.malloc while in a destructor, and "throw new Exception" does that. (In particular, garbage collection has to die without a stack trace, because IT can't throw a new Exception). You might be able to (in theory) emplace an exception in malloc'd or previously allocated memory, but otherwise you can't throw exceptions in a destructor. Or do much of anything.

You could use this function to check if you can alloc memory, and just print out a warning error instead of throwing an exception. But I don't know what else in there might be allocating memory.

cyisfor commented 8 years ago

... or just catch InvalidMemoryOperationError