pr68078.f90 tests out-of-memory handling and calls set_vm_limit to set the
soft limit. However, setrlimit was then called with hard limit RLIM_INFINITY,
which failed when the current hard limit was lower.
gcc/testsuite/
* gfortran.dg/set_vm_limit.c (set_vm_limit): Call getrlimit, use
obtained hard limit, and only call setrlimit if new softlimit is lower.
void
set_vm_limit (int vm_limit)
{
- struct rlimit rl = { vm_limit, RLIM_INFINITY };
+ struct rlimit rl;
int r;
+ r = getrlimit (RLIMIT_AS, &rl);
+ if (r)
+ {
+ perror ("get_vm_limit");
+ exit (1);
+ }
+
+ if (vm_limit >= rl.rlim_cur)
+ return;
+
+ rl.rlim_cur = vm_limit;
r = setrlimit (RLIMIT_AS, &rl);
if (r)
{