Commit 0c09f573 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

alloc and copy pragma_type

parent 62481855
......@@ -100,22 +100,31 @@ struct labcomm_encoder *labcomm_pragma_builder_new(
char * pragma_type) {
struct labcomm_writer *dyn_writer = labcomm_dynamic_buffer_writer_new(
e->memory);
struct labcomm_encoder *mdt = labcomm_encoder_new(dyn_writer,
struct labcomm_encoder *pb = labcomm_encoder_new(dyn_writer,
e->error,
e->memory,
e->scheduler);
size_t tlen = 1+strlen(pragma_type);
char* ptype = labcomm_memory_alloc(
e->memory,
1,
tlen);
if(ptype) {
strncpy(ptype, pragma_type, tlen);
} //XXX TODO: and else?
struct pragma_packet_builder* ctxt = labcomm_memory_alloc(
e->memory,
1,
sizeof(struct pragma_packet_builder));
if(ctxt){
ctxt->pragma_type=pragma_type;
ctxt->pragma_type=ptype;
ctxt->parent=e;
}
mdt->context_type = LABCOMM_PRAGMA;
mdt->context = ctxt;
return mdt;
pb->context_type = LABCOMM_PRAGMA;
pb->context = ctxt;
return pb;
}
//HERE BE DRAGONS! Copied from decoder.c
......@@ -196,6 +205,8 @@ int labcomm_pragma_send(struct labcomm_encoder* e)
err = p->writer->error;
}
free_encoder:
//XXX are these needed, or is that done in encoder_free?
labcomm_memory_free(e->memory, 1, ctx->pragma_type);
labcomm_memory_free(e->memory, 1, ctx);
labcomm_encoder_free(e);
return err;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment