Skip to content

Commit

Permalink
Set some pointers to null after free()ing them (dotnet#47415)
Browse files Browse the repository at this point in the history
These free() calls are done in the middle of the method body; it's
possible that a duplicate free() can be called on these at the cleanup
code that runs before the method returns. So set these pointers to null
after free()ing them to avoid free() already free()d memory.
omajid authored Jan 30, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 6299c9c commit 5846c21
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
@@ -234,7 +234,9 @@ class CGroup
if (filesystemType == nullptr || lineLen > maxLineLen)
{
free(filesystemType);
filesystemType = nullptr;
free(options);
options = nullptr;
filesystemType = (char*)malloc(lineLen+1);
if (filesystemType == nullptr)
goto done;
@@ -321,7 +323,9 @@ class CGroup
if (subsystem_list == nullptr || lineLen > maxLineLen)
{
free(subsystem_list);
subsystem_list = nullptr;
free(cgroup_path);
cgroup_path = nullptr;
subsystem_list = (char*)malloc(lineLen+1);
if (subsystem_list == nullptr)
goto done;
4 changes: 4 additions & 0 deletions src/coreclr/pal/src/misc/cgroup.cpp
Original file line number Diff line number Diff line change
@@ -222,7 +222,9 @@ class CGroup
if (filesystemType == nullptr || lineLen > maxLineLen)
{
PAL_free(filesystemType);
filesystemType = nullptr;
PAL_free(options);
options = nullptr;
filesystemType = (char*)PAL_malloc(lineLen+1);
if (filesystemType == nullptr)
goto done;
@@ -308,7 +310,9 @@ class CGroup
if (subsystem_list == nullptr || lineLen > maxLineLen)
{
PAL_free(subsystem_list);
subsystem_list = nullptr;
PAL_free(cgroup_path);
cgroup_path = nullptr;
subsystem_list = (char*)PAL_malloc(lineLen+1);
if (subsystem_list == nullptr)
goto done;

0 comments on commit 5846c21

Please sign in to comment.