Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
this updates cache structure before the alloc_mem call so that the
structure is intact even in case of an allocation failure
  • Loading branch information
rrrrrrmb committed Oct 7, 2024
1 parent 9950824 commit 26a252e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ add_page( struct cache *c ) {
if( !new_pages ) {
return -1;
}
c->pages = new_pages;

new_page = alloc_mem( c->page_size );
if( !new_page ) {
Expand All @@ -80,7 +81,6 @@ add_page( struct cache *c ) {
new_page_index = c->page_count;
c->page_count++;

c->pages = new_pages;
c->pages[new_page_index] = new_page;
init_page( c, new_page_index );

Expand Down

0 comments on commit 26a252e

Please sign in to comment.