Skip to content

_getdns_context_write_priv_file may call fclose twice #546

@mistr

Description

@mistr

In the function _getdns_context_write_priv_file, after the failure of rename, fclose(f) will be called a second time. You should reset the f and fd variables.

	else if (fclose(f))
		_getdns_log(&context->log
		           , GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
		           , "Error closing temporary file \"%s\": %s (%p)\n"
			    , tmpfn, _getdns_fileerrnostr(), f);

	else if (rename(tmpfn, path) < 0) {
        f = NULL;
        fd = -1;
		_getdns_log(&context->log
		           , GETDNS_LOG_SYS_ANCHOR, GETDNS_LOG_ERR
		           , "Error renaming temporary file \"%s\" to \"%s\""
			     ": %s\n", tmpfn, path, _getdns_fileerrnostr());
    }
	else {
		context->can_write_appdata = PROP_ABLE;
		return 1;
	}
	if (f)
		(void) fclose(f);

	else if (fd >= 0)
		(void) close(fd);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions