Skip to content

Commit

Permalink
Check that malloc succeeded when building cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Diethelm committed Jan 15, 2017
1 parent 1b43c8c commit 55b6e29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cache.xs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ CODE:
size = CACHE_DEFAULT_SIZE;
}
RETVAL = cache_build(aTHX_ size);
if (!RETVAL) {
croak("could not create cache");
}
}
OUTPUT: RETVAL

Expand Down
7 changes: 4 additions & 3 deletions lru.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Cache* cache_build(pTHX_ int size)
{
Cache* cache;
GMEM_NEW(cache, Cache*, sizeof(Cache));
cache->size = size;
cache->data = 0;
/* fprintf(stderr, "LOG building cache for %d elements\n", cache->size); */
if (cache) {
cache->size = size;
cache->data = 0;
}
return cache;
}

Expand Down

0 comments on commit 55b6e29

Please sign in to comment.