summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-06-22 10:53:24 +0200
committerAlexander Larsson <alexl@redhat.com>2010-06-22 10:53:24 +0200
commit9123e24e7b68ad36d4ac2b8f325ea249a5ea9ff5 (patch)
tree2af4db555c749d23e826b617d3f4fece63cd5c7a /client
parentae1de849acd1e58772dc3f318324ed936ff5f21c (diff)
downloadspice-9123e24e7b68ad36d4ac2b8f325ea249a5ea9ff5.tar.gz
spice-9123e24e7b68ad36d4ac2b8f325ea249a5ea9ff5.tar.xz
spice-9123e24e7b68ad36d4ac2b8f325ea249a5ea9ff5.zip
Add destructor for demarshalled messages
This is required because we don't want to free messages that just refer to the unparsed message (like SpiceMsgData). Also, in the future we might need it for more complex demarshalling.
Diffstat (limited to 'client')
-rw-r--r--client/demarshallers.h4
-rw-r--r--client/red_channel.h9
2 files changed, 8 insertions, 5 deletions
diff --git a/client/demarshallers.h b/client/demarshallers.h
index 81189735..ab0fc58c 100644
--- a/client/demarshallers.h
+++ b/client/demarshallers.h
@@ -17,7 +17,9 @@
#ifndef _H_DEMARSHAL
#define _H_DEMARSHAL
-typedef uint8_t * (*spice_parse_channel_func_t)(uint8_t *message_start, uint8_t *message_end, uint16_t message_type, int minor, size_t *size_out);
+typedef void (*message_destructor_t)(uint8_t *message);
+typedef uint8_t * (*spice_parse_channel_func_t)(uint8_t *message_start, uint8_t *message_end, uint16_t message_type, int minor,
+ size_t *size_out, message_destructor_t *free_message);
spice_parse_channel_func_t spice_get_server_channel_parser(uint32_t channel, unsigned int *max_message_type);
diff --git a/client/red_channel.h b/client/red_channel.h
index a9d3ee54..c2528abe 100644
--- a/client/red_channel.h
+++ b/client/red_channel.h
@@ -265,6 +265,7 @@ void MessageHandlerImp<HandlerClass, channel_id>::handle_message(RedPeer::Compun
uint16_t type;
uint32_t size;
size_t parsed_size;
+ message_destructor_t parsed_free;
if (message.sub_list()) {
SpiceSubMessageList *sub_list;
@@ -274,7 +275,7 @@ void MessageHandlerImp<HandlerClass, channel_id>::handle_message(RedPeer::Compun
msg = (uint8_t *)(sub + 1);
type = sub->type;
size = sub->size;
- parsed = _parser(msg, msg + size, type, _obj.get_peer_minor(), &parsed_size);
+ parsed = _parser(msg, msg + size, type, _obj.get_peer_minor(), &parsed_size, &parsed_free);
if (parsed == NULL) {
THROW("failed to parse message type %d", type);
@@ -283,14 +284,14 @@ void MessageHandlerImp<HandlerClass, channel_id>::handle_message(RedPeer::Compun
RedPeer::InMessage sub_message(type, parsed_size, parsed);
(_obj.*_handlers[type])(&sub_message);
- free(parsed);
+ parsed_free(parsed);
}
}
msg = message.data();
type = message.type();
size = message.size();
- parsed = _parser(msg, msg + size, type, _obj.get_peer_minor(), &parsed_size);
+ parsed = _parser(msg, msg + size, type, _obj.get_peer_minor(), &parsed_size, &parsed_free);
RedPeer::InMessage main_message(type, parsed_size, parsed);
if (parsed == NULL) {
@@ -298,7 +299,7 @@ void MessageHandlerImp<HandlerClass, channel_id>::handle_message(RedPeer::Compun
}
(_obj.*_handlers[type])(&main_message);
- free(parsed);
+ parsed_free(parsed);
}
template <class HandlerClass, unsigned int channel_id>