mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
OOM check
This commit is contained in:
@@ -295,6 +295,8 @@ static struct shrmap_slot *
|
|||||||
shrstr_newpage(int sz) {
|
shrstr_newpage(int sz) {
|
||||||
int i;
|
int i;
|
||||||
struct shrmap_slot * s = (struct shrmap_slot *)malloc(sz * sizeof(*s));
|
struct shrmap_slot * s = (struct shrmap_slot *)malloc(sz * sizeof(*s));
|
||||||
|
if (s == NULL)
|
||||||
|
return NULL;
|
||||||
for (i=0;i<sz;i++) {
|
for (i=0;i<sz;i++) {
|
||||||
rwlock_init(&s[i].lock);
|
rwlock_init(&s[i].lock);
|
||||||
s[i].str = NULL;
|
s[i].str = NULL;
|
||||||
@@ -374,6 +376,8 @@ shrstr_expandpage(int cap) {
|
|||||||
sz = sz * 2;
|
sz = sz * 2;
|
||||||
}
|
}
|
||||||
struct shrmap_slot * newpage = shrstr_newpage(sz);
|
struct shrmap_slot * newpage = shrstr_newpage(sz);
|
||||||
|
if (newpage == NULL)
|
||||||
|
return;
|
||||||
rwlock_wlock(&s->lock);
|
rwlock_wlock(&s->lock);
|
||||||
int succ = shrstr_allocpage(s, osz, sz, newpage);
|
int succ = shrstr_allocpage(s, osz, sz, newpage);
|
||||||
rwlock_wunlock(&s->lock);
|
rwlock_wunlock(&s->lock);
|
||||||
|
|||||||
Reference in New Issue
Block a user