Skip to content

Commit 74cf90a

Browse files
MarenzAbscissa
authored andcommitted
Prepared: Prevent mem allocs during cleanup (#138)
If a prepared statement is collected during a GC run and the d'tor is called, it causes another allocation through either: - allocation of the packet array - allocation of an exception when trying to write to a closed connection In both cases, the GC freaks out and throws an InvalidMemoryOperation. This commit fixes the two allocation cases I found. There may be more.
1 parent 04e12fd commit 74cf90a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

source/mysql/prepared.d

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,9 @@ public:
10921092
10931093
This method tells the server that it can dispose of the information it
10941094
holds about the current prepared statement.
1095+
1096+
This method can be called during a GC collection. Allocations should be
1097+
avoided if possible as it could crash the GC.
10951098
+/
10961099
void release()
10971100
{
@@ -1100,8 +1103,11 @@ public:
11001103

11011104
scope(failure) _conn.kill();
11021105

1103-
ubyte[] packet;
1104-
packet.length = 9;
1106+
if (_conn.closed())
1107+
return;
1108+
1109+
ubyte[9] packet_buf;
1110+
ubyte[] packet = packet_buf;
11051111
packet.setPacketHeader(0/*packet number*/);
11061112
_conn.bumpPacket();
11071113
packet[4] = CommandType.STMT_CLOSE;

0 commit comments

Comments
 (0)