drisw: Properly mark shmid as -1 when alloc fails

Cc: mesa-stable
(cherry picked from commit b93bf19d94)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40359>
This commit is contained in:
Lucas Fryzek 2025-05-26 19:36:38 -04:00 committed by Eric Engestrom
parent 681de5a641
commit 8d313e5d1c
2 changed files with 7 additions and 3 deletions

View file

@ -2434,7 +2434,7 @@
"description": "drisw: Properly mark shmid as -1 when alloc fails",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -108,15 +108,19 @@ alloc_shm(struct dri_sw_displaytarget *dri_sw_dt, unsigned size)
/* 0600 = user read+write */
dri_sw_dt->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600);
if (dri_sw_dt->shmid < 0)
if (dri_sw_dt->shmid < 0) {
dri_sw_dt->shmid = -1;
return NULL;
}
addr = (char *) shmat(dri_sw_dt->shmid, NULL, 0);
/* mark the segment immediately for deletion to avoid leaks */
shmctl(dri_sw_dt->shmid, IPC_RMID, NULL);
if (addr == (char *) -1)
if (addr == (char *) -1) {
dri_sw_dt->shmid = -1;
return NULL;
}
return addr;
}