efl core cmommand line - implement destructor and thus fix leak

This commit is contained in:
Carsten Haitzler 2019-09-10 17:29:01 +01:00
parent 38be95b0b6
commit e51699afbc
2 changed files with 22 additions and 2 deletions

View File

@ -203,6 +203,16 @@ _remove_invalid_chars(char *command)
}
}
static void
_clear_command(Efl_Core_Command_Line_Data *pd)
{
if (!pd->command) return;
while (eina_array_count(pd->command) > 0)
eina_stringshare_del(eina_array_pop(pd->command));
eina_array_free(pd->command);
pd->command = NULL;
}
EOLIAN static Eina_Bool
_efl_core_command_line_command_array_set(Eo *obj EINA_UNUSED, Efl_Core_Command_Line_Data *pd, Eina_Array *array)
{
@ -210,6 +220,7 @@ _efl_core_command_line_command_array_set(Eo *obj EINA_UNUSED, Efl_Core_Command_L
Eina_Strbuf *command = eina_strbuf_new();
unsigned int i = 0;
_clear_command(pd);
pd->command = eina_array_new(array ? eina_array_count(array) : 0);
for (i = 0; i < (array ? eina_array_count(array) : 0); ++i)
{
@ -219,7 +230,6 @@ _efl_core_command_line_command_array_set(Eo *obj EINA_UNUSED, Efl_Core_Command_L
if (!param)
{
free(param);
while (eina_array_count(pd->command) > 0)
eina_stringshare_del(eina_array_pop(pd->command));
eina_array_free(pd->command);
@ -276,4 +286,11 @@ _efl_core_command_line_command_string_set(Eo *obj EINA_UNUSED, Efl_Core_Command_
return EINA_TRUE;
}
EOLIAN static void
_efl_core_command_line_efl_object_destructor(Eo *obj EINA_UNUSED, Efl_Core_Command_Line_Data *pd)
{
free(pd->string_command);
pd->string_command = NULL;
_clear_command(pd);
}
#include "efl_core_command_line.eo.c"

View File

@ -1,4 +1,4 @@
mixin @beta Efl.Core.Command_Line {
mixin @beta Efl.Core.Command_Line requires Efl.Object {
[[A mixin that implements standard functions for command lines.
This object parses the command line that gets passed, later the object can be accessed via accessor or the string
@ -79,4 +79,7 @@ mixin @beta Efl.Core.Command_Line {
}
}
implements {
Efl.Object.destructor;
}
}