hackers-painters / katana-parser

A CSS parsing library in pure C99
http://hackers-painters.github.io/katana-parser
MIT License
180 stars 40 forks source link

KatanaError objects are leaked. #21

Open vs-savchenko opened 5 years ago

vs-savchenko commented 5 years ago

Error objects are allocated on the heap and are not freed when KatanaOutput object is destroyed.

Function katana_destroy_output:

...

katana_destroy_stylesheet(&parser, output->stylesheet);

katana_array_destroy(&parser, &output->errors); // here should be katana_destroy_array call instead

katana_parser_deallocate(&parser, output);

...

mjrgh commented 5 years ago

Fix is to add this at parser.c line 171 (before katana_array_destroy(...output->errors)):

{
   unsigned int i;
   for (i = 0; i < output->errors.length; ++i)
     free(output->errors.data[i]);
}
vs-savchenko commented 5 years ago

Thanks for your replay. I actually did it like this:

void katana_destroy_error(KatanaParser* parser, KatanaError* e);

void katana_destroy_error(KatanaParser* parser, KatanaError* e)
{
    if ( e ) {
        katana_parser_deallocate(parser, (void*) e);
    }
}

line: 172 (before katana_parser_deallocate(&parser, output);) katana_destroy_array(&parser, katana_destroy_error, &output->errors);