Correctly copy sr_datafeed_meta in sr_packet_copy().

Commit 5801d558 replaced g_slist_copy_deep() by some incorrect code
that actually leaks the newly allocated memory, instead of doing
a deep copy.

This new version should be more correct, more concise, and it fixes
the following warning:

src/session.c: In function 'sr_packet_copy':
src/session.c:1025:38: warning: passing argument 2 of 'g_slist_foreach' from incompatible pointer type [-Wincompatible-pointer-types]
   g_slist_foreach(meta_copy->config, (GCopyFunc)copy_src, NULL);
                                         ^
In file included from /usr/include/glib-2.0/glib/gmain.h:26:0,
                 from /usr/include/glib-2.0/glib/giochannel.h:33,
                 from /usr/include/glib-2.0/glib.h:54,
                 from src/session.c:24:
/usr/include/glib-2.0/glib/gslist.h:125:10: note: expected 'GFunc {aka void (*)(void *, void *)}' but argument is of type 'void * (*)(const void *, void *)'
void     g_slist_foreach                 (GSList           *list,
         ^
This commit is contained in:
Aurelien Jacobs 2015-02-12 11:14:37 +01:00
parent c4f9582714
commit ee29d92e14
1 changed files with 5 additions and 10 deletions

View File

@ -983,15 +983,11 @@ SR_API int sr_session_source_remove_channel(struct sr_session *session,
return _sr_session_source_remove(session, (gintptr)channel); return _sr_session_source_remove(session, (gintptr)channel);
} }
static void *copy_src(struct sr_config *src) static void copy_src(struct sr_config *src, struct sr_datafeed_meta *meta_copy)
{ {
struct sr_config *new_src;
new_src = g_malloc(sizeof(struct sr_config));
memcpy(new_src, src, sizeof(struct sr_config));
g_variant_ref(src->data); g_variant_ref(src->data);
meta_copy->config = g_slist_append(meta_copy->config,
return new_src; g_memdup(src, sizeof(struct sr_config)));
} }
SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet, SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet,
@ -1020,9 +1016,8 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet,
break; break;
case SR_DF_META: case SR_DF_META:
meta = packet->payload; meta = packet->payload;
meta_copy = g_malloc(sizeof(struct sr_datafeed_meta)); meta_copy = g_malloc0(sizeof(struct sr_datafeed_meta));
meta_copy->config = g_slist_copy(meta->config); g_slist_foreach(meta->config, (GFunc)copy_src, meta_copy->config);
g_slist_foreach(meta_copy->config, (GCopyFunc)copy_src, NULL);
(*copy)->payload = meta_copy; (*copy)->payload = meta_copy;
break; break;
case SR_DF_LOGIC: case SR_DF_LOGIC: