The function was supposed to create a deep copy
of a filterspec list, which it generally seemed
to do if everything went fine.
However:
* if copying the first filterspec element failed,
the *original* elements were all freed, which
resulted in dangling pointers.
* if copying the N+1'th filterspec failed, any
subsequent filterspecs were removed from the
*original* as well.
* if everything succeeded, the original object
actually got a copy of the list, and the new
object got the original list.
Change-Id: I064b54d505c471fb042b036cf72398fb0fa5297c
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
/**
* Returns a deep copy of the passed object.
*/
-log_format *log_format_from_format(log_format *p_format);
+log_format *log_format_from_format(const log_format *p_format);
/**
* Returns FORMAT_OFF on invalid string
* @return The new structure (or NULL if allocation failed)
* @see log_format_free
*/
-log_format *log_format_from_format(log_format *p_format)
+log_format *log_format_from_format(const log_format *p_format)
{
log_format *p_ret;
FilterInfo *p_info, *p_info_old = NULL;
if (!(p_ret = log_format_new()))
return NULL;
- *p_ret = *p_format;
+ p_ret->format = p_format->format;
+ p_ret->global_pri = p_format->global_pri;
+ p_ret->exact_global_pri = p_format->exact_global_pri;
+ p_ret->filters = NULL;
p_info = p_format->filters;
}
if (!p_info_old)
- p_format->filters = p_tmp;
+ p_ret->filters = p_tmp;
else
p_info_old->p_next = p_tmp;