Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some crashes caused by running out of memory #3825

Merged
merged 6 commits into from
Jan 7, 2020
Merged
Prev Previous commit
Next Next commit
Make CollectBags return 0 when it cannot allocate enough space
Previously CollectBags would sometimes return 0, and sometimes
Panic. Also, cleanup was not handled properly
  • Loading branch information
ChrisJefferson authored and fingolfin committed Jan 6, 2020
commit 65bb532b9eff9cb585050aba3654017cc5090dd9
4 changes: 2 additions & 2 deletions src/gasman.c
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ static Int CollectBags_Check(UInt size, UInt FullBags, UInt nrBags)

// Check if this allocation would even fit into memory
if (SIZE_MAX - (size_t)(sizeof(BagHeader) + size) < (size_t)AllocBags) {
return 0;
return 2; // signal error
}

// store in 'stopBags' where this allocation takes us
Expand Down Expand Up @@ -2141,7 +2141,7 @@ static Int CollectBags_Check(UInt size, UInt FullBags, UInt nrBags)

/* get the storage we absolutely need */
while ( EndBags < stopBags
&& SyAllocBags(512,1) )
&& SyAllocBags(512,0) )
EndBags += WORDS_BAG(512*1024L);

/* if not enough storage is free, fail */
Expand Down