Fix kernel memory leak in pNotifShare

This commit is contained in:
miaotianxiang 2024-06-05 15:46:39 +08:00
parent e45d91de02
commit bd90c1b478
2 changed files with 15 additions and 1 deletions

View File

@ -395,7 +395,6 @@ eventInit_IMPL
*pppEventNotification = inotifyGetNotificationListPtr(pNotifierShare->pNotifier);
}
serverRefShare(&g_resServ, staticCast(pNotifierShare, RsShared));
pEvent->pNotifierShare = pNotifierShare;
// RS-TODO these can be looked up from share
@ -427,6 +426,7 @@ notifyGetOrAllocNotifShare_IMPL
if (pNotifierShare == NULL)
{
RsShared *pShare;
// serverAllocShare() sets pNotifierShare->refCount to 1.
status = serverAllocShare(&g_resServ, classInfo(NotifShare), &pShare);
if (status != NV_OK)
return status;
@ -437,6 +437,14 @@ notifyGetOrAllocNotifShare_IMPL
pNotifierShare->hNotifierResource = hNotifierResource;
inotifySetNotificationShare(staticCast(pNotifier, INotifier), pNotifierShare);
}
else
{
// Move serverRefShare() from eventInit_IMPL to here, so that |pNotifierShare|
// can be refcounted correctly.
//
// serverRefShare() increments pNotifierShare->refCount.
serverRefShare(&g_resServ, staticCast(pNotifierShare, RsShared));
}
if (ppNotifierShare)
*ppNotifierShare = pNotifierShare;

View File

@ -1109,4 +1109,10 @@ shrnotifDestruct_IMPL
NotifShare *pNotifShare
)
{
// pNotifier->pNotifierShare should be set to NULL, or inotifyGetNotificationShare() would
// return invalid/wild pointer and cause kernel crash.
if (pNotifShare->pNotifier != NULL)
{
inotifySetNotificationShare(pNotifShare->pNotifier, NULL);
}
}