From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-x232.google.com (mail-lf0-x232.google.com [IPv6:2a00:1450:4010:c07::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C4253803B2 for ; Fri, 24 Mar 2017 00:07:16 -0700 (PDT) Received: by mail-lf0-x232.google.com with SMTP id z15so2144933lfd.1 for ; Fri, 24 Mar 2017 00:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=B+jaQCf0nE54ES/QQdwtQjWZ+WM/4avowOnlVrW16go=; b=GVuxvOWpkWXW+mglxF/4Oqu8zJVG9v2FApBAptPWIN48swEMfHXFwAJrk0S5yVKecl Yquiuraiq13RdKk5yKv/ePYKzSJGu5W6dflHb8AGBqjtaR0m209th4S4OYOjdnspcqx5 yAnWo4IbP+NPkhiFcvZhZL35KpP/dfbOXb2NH7Kr3eS6KWWKrequfpwszqVyWb1qReJo fJ8TngNA/+yTw9Pt8V6u5GiNieMA0EYzrE61oVw334pHTZBkCwXW6BCD1WkTyh0p3luL MXt7PJCnXepOKGynsUXmjlIRhqJeai63Jo7i7EEt9291mkYYZiy7tvoqAnCdg9RmBJHC fSqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=B+jaQCf0nE54ES/QQdwtQjWZ+WM/4avowOnlVrW16go=; b=c5Z9XOUt1mJ+M1XdDsqd8qj9nFv+uj15QC8UmeouiL4HAv12S4Qr0MLFAWxQeyXK/q r6pDmdn/qCym/qnIyRdymkLjLeX1EuQ7g61OlGAJC5rUL4jpF6rUP1CWLo7NTeDMfmsO uY/VxUU2dM435v2WbPN8DoEwdyESTGfJ0HmLpxTkSTmHMqbrm0rmfQSRroAdiCY6ZGCL 40OUDKJWAQYkEKu7DBbEIbp9FeqHhhPzHNZehq0pDMiJFgpJGRlDwryOa+fPZV53YjJV wigqPLrGMqDtPo6wYfZZyQgOeKhtJNDzqHFwro/sIVTm+fwqXVqTzf5dqqPPVKuAuMJM p38A== X-Gm-Message-State: AFeK/H3QvMFQXUmX7Mnz6anwTmaA5KZzbVWVFRfpErpYh+dfNZDMX7VVOSTmEWor3l2b1UDyVJ/6t681O8y/iQ== X-Received: by 10.25.93.86 with SMTP id p22mr3416478lfj.9.1490339234824; Fri, 24 Mar 2017 00:07:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.72.213 with HTTP; Fri, 24 Mar 2017 00:07:14 -0700 (PDT) In-Reply-To: <9C33D691-C2DF-4F19-933D-5D344B96554B@apple.com> References: <9C33D691-C2DF-4F19-933D-5D344B96554B@apple.com> From: Arka Sharma Date: Fri, 24 Mar 2017 12:37:14 +0530 Message-ID: To: Andrew Fish Cc: edk2-devel@lists.01.org Subject: Re: Closing events and releasing resources in notify function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Mar 2017 07:07:17 -0000 Content-Type: text/plain; charset=UTF-8 Thanks Andrew for your reply. In this case I am creating the event with CreateEvent() and not with CreateEventEx(). I am attempting to free the Context inside the notify function which will be called after Event is signaled, and Context is only accessed before CreateEvent() and inside the NotifyRoutine(). So the change you are suggesting is inside the notify function I should call CloseEvent() first before freeing Context right ? On Fri, Mar 24, 2017 at 12:07 PM, Andrew Fish wrote: > >> On Mar 23, 2017, at 11:22 PM, Arka Sharma wrote: >> >> Hi, >> >> Is it ok to close the event and release the resource allocated to be >> sent as context inside the notify function. May be something like this >> >> VOID >> EFIAPI >> NotifyRoutine ( >> EFI_EVENT Event, >> VOID *Context >> ) >> { >> // >> // Perform intended task >> // >> FreePool (Context); >> gBS->CloseEvent (Event); > > You should close the event before you free the context, or you will have a race. You need to make sure there is no way for EFI to signal the event before you free the context. > > This all assumes you don't have other code doing crazy stuff with the Context or Event. It would be a different answer for CreateEventEx() > > Thanks, > > Andrew Fish > >> } >> >> In the above example Context was allocated before creating the event >> and passed as a parameter to CreateEvent(). >> >> Regards, >> Arka >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel >