cmdline iface - fix to consume input array AND strings totally

strings often enough are generated e.g. via "%s/%s" or "%i" or similar
etc. ... i have poitned to examples, so move to make all strings
consistently stringshared, fix a bug added to the efl thread code
where it accessed and freed array even tho array was consumed (but not
strings) in the set, and the code used free to consume not
stringshare_del. fix other code and tests to match

EXCTLY the kind of bugs and mistakes with this kind of design that i
said would happen more often just happened...
This commit is contained in:
Carsten Haitzler 2019-02-14 11:28:23 +00:00
parent 9d65e64c00
commit 8e98c7eef9
5 changed files with 16 additions and 12 deletions

View File

@ -223,6 +223,8 @@ _efl_core_command_line_command_array_set(Eo *obj EINA_UNUSED, Efl_Core_Command_L
eina_stringshare_del(eina_array_pop(pd->command));
eina_array_free(pd->command);
pd->command = NULL;
for (;i < (array ? eina_array_count(array) : 0); ++i)
eina_stringshare_del(content);
eina_array_free(array);
return EINA_FALSE;
}
@ -236,6 +238,7 @@ _efl_core_command_line_command_array_set(Eo *obj EINA_UNUSED, Efl_Core_Command_L
_remove_invalid_chars(param);
eina_array_push(pd->command, eina_stringshare_add(param));
free(param);
eina_stringshare_del(content);
}
pd->string_command = eina_strbuf_release(command);
pd->filled = EINA_TRUE;

View File

@ -60,7 +60,7 @@ mixin @beta Efl.Core.Command_Line {
return : bool; [[On success $true, $false otherwise]]
}
values {
array : array<string> @owned; [[An array where every array field is an argument]]
array : array<const(stringshare)> @owned; [[An array where every array field is an argument]]
}
}
@property command_string {

View File

@ -390,8 +390,11 @@ ecore_loop_arguments_send(int argc, const char **argv)
cml = eina_array_new(argc);
for (i = 0; i < argc; i++)
{
Eina_Stringshare *arg = eina_stringshare_add(argv[i]);
Eina_Stringshare *arg;
arg = eina_stringshare_add(argv[i]);
eina_array_push(arga, arg);
arg = eina_stringshare_add(argv[i]);
eina_array_push(cml, arg);
}

View File

@ -277,11 +277,9 @@ _efl_thread_main(void *data, Eina_Thread t)
it->func, it->user_data);
}
efl_core_command_line_command_array_set(obj, thdat->argv);
thdat->argv = NULL;
efl_future_then(obj, efl_loop_job(obj),
.success = _efl_loop_arguments_send);
while (thdat->argv && eina_array_count(thdat->argv)) free(eina_array_pop(thdat->argv));
eina_array_free(thdat->argv);
free(thdat->event_cb);
thdat->event_cb = NULL;

View File

@ -23,13 +23,13 @@ _construct_array(void)
{
Eina_Array *array = eina_array_new(16);
eina_array_push(array, "/bin/sh");
eina_array_push(array, "-C");
eina_array_push(array, "foo");
eina_array_push(array, "--test");
eina_array_push(array, "--option=done");
eina_array_push(array, "--");
eina_array_push(array, "asdf --test");
eina_array_push(array, eina_stringshare_add("/bin/sh"));
eina_array_push(array, eina_stringshare_add("-C"));
eina_array_push(array, eina_stringshare_add("foo"));
eina_array_push(array, eina_stringshare_add("--test"));
eina_array_push(array, eina_stringshare_add("--option=done"));
eina_array_push(array, eina_stringshare_add("--"));
eina_array_push(array, eina_stringshare_add("asdf --test"));
return array;
}