Skip to content

Commit 06c5190

Browse files
author
Matias Martini
committed
Fix(client) Set dangling pointer to NULL after client closure
We recently encountered an unexpected Segmentation Fault Error while checking if a client was dead after closing it. Upon investigation, we discovered that the issue was caused by deallocating all memory used by the client structure without setting the pointer to NULL after closing the client connection through dbclose. This resulted in a dangling pointer, which led to the Segmentation Fault when we tried to check whether the client was dead using TDS dbdead. To prevent this issue from occurring again, I have made the necessary updates to set the client pointer to NULL after every dbclose. This will ensure that we avoid any dangling pointers and keep our code running smoothly.
1 parent 1859c26 commit 06c5190

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

ext/tiny_tds/client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static void rb_tinytds_client_free(void *ptr) {
232232
dbloginfree(cwrap->login);
233233
if (cwrap->client && !cwrap->closed) {
234234
dbclose(cwrap->client);
235+
cwrap->client = NULL;
235236
cwrap->closed = 1;
236237
cwrap->userdata->closed = 1;
237238
}
@@ -263,6 +264,7 @@ static VALUE rb_tinytds_close(VALUE self) {
263264
GET_CLIENT_WRAPPER(self);
264265
if (cwrap->client && !cwrap->closed) {
265266
dbclose(cwrap->client);
267+
cwrap->client = NULL;
266268
cwrap->closed = 1;
267269
cwrap->userdata->closed = 1;
268270
}

0 commit comments

Comments
 (0)