mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 05:58:33 +00:00
Replace alloc() with xmalloc() and remove immediate OOM checks
This commit is contained in:
@@ -104,11 +104,9 @@ static void mf_hash_grow(mf_hashtab_T *);
|
||||
*/
|
||||
memfile_T *mf_open(char_u *fname, int flags)
|
||||
{
|
||||
memfile_T *mfp;
|
||||
off_t size;
|
||||
|
||||
if ((mfp = (memfile_T *)alloc((unsigned)sizeof(memfile_T))) == NULL)
|
||||
return NULL;
|
||||
memfile_T *mfp = xmalloc(sizeof(memfile_T));
|
||||
|
||||
if (fname == NULL) { /* no file for this memfile, use memory only */
|
||||
mfp->mf_fname = NULL;
|
||||
@@ -323,8 +321,7 @@ bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count)
|
||||
freep->bh_bnum += page_count;
|
||||
freep->bh_page_count -= page_count;
|
||||
} else if (hp == NULL) { /* need to allocate memory for this block */
|
||||
if ((p = (char_u *)alloc(mfp->mf_page_size * page_count)) == NULL)
|
||||
return NULL;
|
||||
p = xmalloc(mfp->mf_page_size * page_count);
|
||||
hp = mf_rem_free(mfp);
|
||||
hp->bh_data = p;
|
||||
} else { /* use the number, remove entry from free list */
|
||||
@@ -690,10 +687,7 @@ static bhdr_T *mf_release(memfile_T *mfp, int page_count)
|
||||
*/
|
||||
if (hp->bh_page_count != page_count) {
|
||||
free(hp->bh_data);
|
||||
if ((hp->bh_data = alloc(mfp->mf_page_size * page_count)) == NULL) {
|
||||
free(hp);
|
||||
return NULL;
|
||||
}
|
||||
hp->bh_data = xmalloc(mfp->mf_page_size * page_count);
|
||||
hp->bh_page_count = page_count;
|
||||
}
|
||||
return hp;
|
||||
@@ -744,16 +738,10 @@ int mf_release_all(void)
|
||||
*/
|
||||
static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, int page_count)
|
||||
{
|
||||
bhdr_T *hp;
|
||||
bhdr_T *hp = xmalloc(sizeof(bhdr_T));
|
||||
hp->bh_data = xmalloc(mfp->mf_page_size * page_count);
|
||||
hp->bh_page_count = page_count;
|
||||
|
||||
if ((hp = (bhdr_T *)alloc((unsigned)sizeof(bhdr_T))) != NULL) {
|
||||
if ((hp->bh_data = (char_u *)alloc(mfp->mf_page_size * page_count))
|
||||
== NULL) {
|
||||
free(hp); /* not enough memory */
|
||||
return NULL;
|
||||
}
|
||||
hp->bh_page_count = page_count;
|
||||
}
|
||||
return hp;
|
||||
}
|
||||
|
||||
@@ -925,14 +913,12 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
|
||||
{
|
||||
bhdr_T *freep;
|
||||
blocknr_T new_bnum;
|
||||
NR_TRANS *np;
|
||||
int page_count;
|
||||
|
||||
if (hp->bh_bnum >= 0) /* it's already positive */
|
||||
return OK;
|
||||
|
||||
if ((np = (NR_TRANS *)alloc((unsigned)sizeof(NR_TRANS))) == NULL)
|
||||
return FAIL;
|
||||
NR_TRANS *np = xmalloc(sizeof(NR_TRANS));
|
||||
|
||||
/*
|
||||
* Get a new number for the block.
|
||||
|
Reference in New Issue
Block a user