Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
hsearch_r: Apply VM size limit in test case
  • Loading branch information
Florian Weimer committed Feb 12, 2016
1 parent e535ce2 commit f34f146
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2016-02-12 Florian Weimer <fweimer@redhat.com>

* misc/bug18240.c (do_test): Set RLIMIT_AS.

2016-02-11 Szabolcs Nagy <szabolcs.nagy@arm.com>

[BZ #19529]
Expand Down
22 changes: 22 additions & 0 deletions misc/bug18240.c
Expand Up @@ -22,6 +22,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>

static void
test_size (size_t size)
Expand Down Expand Up @@ -58,6 +59,27 @@ test_size (size_t size)
static int
do_test (void)
{
/* Limit the size of the process, so that memory allocation will
fail without impacting the entire system. */
{
struct rlimit limit;
if (getrlimit (RLIMIT_AS, &limit) != 0)
{
printf ("getrlimit (RLIMIT_AS) failed: %m\n");
return 1;
}
long target = 100 * 1024 * 1024;
if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > target)
{
limit.rlim_cur = target;
if (setrlimit (RLIMIT_AS, &limit) != 0)
{
printf ("setrlimit (RLIMIT_AS) failed: %m\n");
return 1;
}
}
}

test_size (500);
test_size (-1);
test_size (-3);
Expand Down

0 comments on commit f34f146

Please sign in to comment.