Skip to content

Commit c38ebb4

Browse files
[3.12] gh-113343: Fix error check on mmap(2) (GH-113342) (#113374)
gh-113343: Fix error check on mmap(2) (GH-113342) Fix error check on mmap(2) It should check MAP_FAILED instead of NULL for error. On mmap(2) man page: RETURN VALUE On success, mmap() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the error. (cherry picked from commit 6b70c3d) Co-authored-by: Namhyung Kim <[email protected]>
1 parent 8836c2d commit c38ebb4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Python/perf_trampoline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ new_code_arena(void)
247247
mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
248248
-1, // fd (not used here)
249249
0); // offset (not used here)
250-
if (!memory) {
250+
if (memory == MAP_FAILED) {
251251
PyErr_SetFromErrno(PyExc_OSError);
252252
_PyErr_WriteUnraisableMsg(
253253
"Failed to create new mmap for perf trampoline", NULL);

0 commit comments

Comments
 (0)