When to free the desc in a multithreaded driver

Sean Hinde Sean.Hinde@REDACTED
Mon Aug 20 21:07:20 CEST 2001


Looking at the file driver, efile_drv.c, I can't quite determine when the
port descriptor gets freed.

In the file_stop() callback, which I have attached below, the desc gets
freed if the fd is zero or the file is compressed, but if the fd is not zero
then an invoke_close callback is scheduled. I can't then see anywhere else
that the desc gets freed.

Two questions arise:

1. If the driver stop callback invokes a function in a thread when should
the descriptor be freed?

2. Depending on the answer to 1, is there therefore a memory leak in


static int file_stop(desc)
file_descriptor* desc;
    int fd = desc->fd;

    if (desc->flags & EFILE_COMPRESSED) {
    } else if (fd >= 0) {
#if 0
/* Threaded close */
	struct t_data *d = sys_alloc(sizeof(struct t_data));
	d->fd = fd;
	d->command = FILE_CLOSE;
	DRIVER_ASYNC(2, desc, KEY, invoke_close, (void *) d,
	return 0;
    return 0;

This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.

More information about the erlang-questions mailing list