ecore exe - fix fix malloc fail handling

for both ecore_exe_win32.c and ecore_exe_posix.c when the rare case
(basically almost never) that malloc fails for the exe read/err
buffers also set the data size to 0 so it doesn't lie with a NULL ptr
for data.

@fix
This commit is contained in:
Carsten Haitzler 2017-09-15 07:44:58 +09:00
parent 0f08ee686e
commit dc137aba43
2 changed files with 18 additions and 10 deletions

View File

@ -711,20 +711,24 @@ _impl_ecore_exe_event_data_get(Ecore_Exe *obj,
exe->read_data_size = i - last;
exe->read_data_buf = malloc(exe->read_data_size);
if (exe->read_data_buf)
memcpy(exe->read_data_buf, c, exe->read_data_size);
else
{
memcpy(exe->read_data_buf, c, exe->read_data_size);
exe->read_data_size = 0;
ERR("Out of memory in allocating exe pipe data");
}
else ERR("Out of memory in allocating exe pipe data");
}
else
{
exe->error_data_size = i - last;
exe->error_data_buf = malloc(exe->error_data_size);
if (exe->error_data_buf)
memcpy(exe->error_data_buf, c, exe->error_data_size);
else
{
memcpy(exe->error_data_buf, c, exe->error_data_size);
exe->error_data_size = 0;
ERR("Out of memory in allocating exe pipe data");
}
else ERR("Out of memory in allocating exe pipe data");
}
}
if (count == 0) /* No lines to send, cancel the event. */

View File

@ -664,23 +664,27 @@ _impl_ecore_exe_event_data_get(Ecore_Exe *obj,
if (count != 0) e->size = last;
if (flags & ECORE_EXE_PIPE_READ)
{
exe->pipe_read.data_size = i - last;
exe->pipe_read.data_buf = malloc(exe->pipe_read.data_size);
if (exe->pipe_read.data_buf)
memcpy(exe->pipe_read.data_buf, c, exe->pipe_read.data_size);
else
{
exe->pipe_read.data_size = i - last;
memcpy(exe->pipe_read.data_buf, c, exe->pipe_read.data_size);
exe->pipe_read.data_size = 0;
ERR("Out of memory in allocating exe pipe data");
}
else ERR("Out of memory in allocating exe pipe data");
}
else
{
exe->pipe_error.data_size = i - last;
exe->pipe_error.data_buf = malloc(exe->pipe_error.data_size);
if (exe->pipe_error.data_buf)
memcpy(exe->pipe_error.data_buf, c, exe->pipe_error.data_size);
else
{
exe->pipe_error.data_size = i - last;
memcpy(exe->pipe_error.data_buf, c, exe->pipe_error.data_size);
exe->pipe_error.data_size = 0;
ERR("Out of memory in allocating exe pipe data");
}
else ERR("Out of memory in allocating exe pipe data");
}
}
if (count == 0) /* No lines to send, cancel the event. */