forked from len0rd/rockbox
move buflib_free invalid handle check to the function
allow buflib_free to check for invalid or already freed handles within the function -- remove all the invalid handle guards thru core_free Change-Id: Ibdcbc82760fc93b674c42283fca420d94907df8e
This commit is contained in:
parent
9d3d925295
commit
12ef045fdf
18 changed files with 32 additions and 62 deletions
|
|
@ -820,6 +820,8 @@ find_block_before(struct buflib_context *ctx, union buflib_data* block,
|
|||
int
|
||||
buflib_free(struct buflib_context *ctx, int handle_num)
|
||||
{
|
||||
if (handle_num <= 0) /* invalid or already free */
|
||||
return handle_num;
|
||||
union buflib_data *handle = ctx->handle_table - handle_num,
|
||||
*freed_block = handle_to_block(ctx, handle_num),
|
||||
*block, *next_block;
|
||||
|
|
|
|||
|
|
@ -1963,8 +1963,7 @@ static int prepare_build(bool *realloced)
|
|||
int handle = reset_buffer();
|
||||
dircache_unlock();
|
||||
|
||||
if (handle > 0)
|
||||
core_free(handle);
|
||||
core_free(handle);
|
||||
|
||||
handle = alloc_cache(size);
|
||||
|
||||
|
|
@ -2164,8 +2163,7 @@ static void dircache_suspend_internal(bool freeit)
|
|||
|
||||
dircache_unlock();
|
||||
|
||||
if (handle > 0)
|
||||
core_free(handle);
|
||||
core_free(handle);
|
||||
|
||||
thread_wait(thread_id);
|
||||
|
||||
|
|
@ -3179,7 +3177,7 @@ error:
|
|||
dircache_unlock();
|
||||
|
||||
error_nolock:
|
||||
if (rc < 0 && handle > 0)
|
||||
if (rc < 0)
|
||||
core_free(handle);
|
||||
|
||||
if (fd >= 0)
|
||||
|
|
|
|||
|
|
@ -237,8 +237,7 @@ static int zip_read_ed(struct zip* z) {
|
|||
rv = 0;
|
||||
|
||||
bail:
|
||||
if (mem_handle >= 0)
|
||||
core_free(mem_handle);
|
||||
core_free(mem_handle);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
@ -337,10 +336,9 @@ static int zip_read_cd(struct zip* z, bool use_cb) {
|
|||
rv = 0;
|
||||
|
||||
bail:
|
||||
if (rv != 0 && cds_handle >= 0)
|
||||
if (rv != 0)
|
||||
core_free(cds_handle);
|
||||
if (mem_handle >= 0)
|
||||
core_free(mem_handle);
|
||||
core_free(mem_handle);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
@ -497,8 +495,7 @@ static int zip_read_entries(struct zip* z) {
|
|||
rv = 0;
|
||||
|
||||
bail:
|
||||
if (mem_handle >= 0)
|
||||
core_free(mem_handle);
|
||||
core_free(mem_handle);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
@ -754,10 +751,8 @@ struct zip* zip_open(const char* name, bool try_mem) {
|
|||
bail:
|
||||
if (file >= 0)
|
||||
close(file);
|
||||
if (mem_handle >= 0)
|
||||
core_free(mem_handle);
|
||||
if (zip_handle >= 0)
|
||||
core_free(zip_handle);
|
||||
core_free(mem_handle);
|
||||
core_free(zip_handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -875,8 +870,7 @@ void zip_close(struct zip* z) {
|
|||
|
||||
z->close(z);
|
||||
|
||||
if (z->cds_handle >= 0)
|
||||
core_free(z->cds_handle);
|
||||
core_free(z->cds_handle);
|
||||
|
||||
core_free(z->zip_handle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -604,8 +604,7 @@ void font_unload(int font_id)
|
|||
glyph_cache_save(font_id);
|
||||
close(pf->fd);
|
||||
}
|
||||
if (handle > 0)
|
||||
core_free(handle);
|
||||
core_free(handle);
|
||||
buflib_allocations[font_id] = -1;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,8 +221,7 @@ int uimage_load(struct uimage_header* uh, size_t* out_size,
|
|||
ret = 0;
|
||||
|
||||
err:
|
||||
if(state_h > 0)
|
||||
core_free(state_h);
|
||||
core_free(state_h);
|
||||
if(out_h > 0) {
|
||||
if(ret == 0)
|
||||
ret = out_h;
|
||||
|
|
|
|||
|
|
@ -178,8 +178,7 @@ static void updater_cleanup(struct updater* u)
|
|||
if(u->tar && mtar_is_open(u->tar))
|
||||
mtar_close(u->tar);
|
||||
|
||||
if(u->buf_hnd >= 0)
|
||||
core_free(u->buf_hnd);
|
||||
core_free(u->buf_hnd);
|
||||
|
||||
if(u->ndrv) {
|
||||
nand_close(u->ndrv);
|
||||
|
|
|
|||
|
|
@ -481,8 +481,7 @@ void usb_storage_init_connection(void)
|
|||
|
||||
void usb_storage_disconnect(void)
|
||||
{
|
||||
if (usb_handle > 0)
|
||||
usb_handle = core_free(usb_handle);
|
||||
usb_handle = core_free(usb_handle);
|
||||
}
|
||||
|
||||
/* called by usb_core_transfer_complete() */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue