Skip to content

Commit

Permalink
Fix memory leak with custom importer not being freed
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Dec 19, 2014
1 parent 763717a commit 1b72808
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sass_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,12 @@ extern "C" {
cur = next;
}
}
// Free custom importer
free(options->importer);
// Free the list container
free(options->c_functions);
// Make it null terminated
options->importer = 0;
options->c_functions = 0;
options->include_paths = 0;
}
Expand Down
6 changes: 6 additions & 0 deletions sass_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ extern "C" {
Sass_C_Import_Fn sass_import_get_function(Sass_C_Import_Callback fn) { return fn->function; }
void* sass_import_get_cookie(Sass_C_Import_Callback fn) { return fn->cookie; }

// Just in case we have some stray import structs
void sass_delete_importer (Sass_C_Import_Callback fn)
{
free(fn);
}

// Creator for sass custom importer return argument list
struct Sass_Import** sass_make_import_list(size_t length)
{
Expand Down
2 changes: 2 additions & 0 deletions sass_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Sass_C_Import_Callback sass_make_importer (Sass_C_Import_Fn, void* cookie);
Sass_C_Import_Fn sass_import_get_function (Sass_C_Import_Callback fn);
void* sass_import_get_cookie (Sass_C_Import_Callback fn);

// Deallocator for associated memory
void sass_delete_importer (Sass_C_Import_Callback fn);

// Creator for sass custom importer return argument list
struct Sass_Import** sass_make_import_list (size_t length);
Expand Down

0 comments on commit 1b72808

Please sign in to comment.