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( ...@@ -100,22 +100,31 @@ struct labcomm_encoder *labcomm_pragma_builder_new(
char * pragma_type) { char * pragma_type) {
struct labcomm_writer *dyn_writer = labcomm_dynamic_buffer_writer_new( struct labcomm_writer *dyn_writer = labcomm_dynamic_buffer_writer_new(
e->memory); e->memory);
struct labcomm_encoder *mdt = labcomm_encoder_new(dyn_writer, struct labcomm_encoder *pb = labcomm_encoder_new(dyn_writer,
e->error, e->error,
e->memory, e->memory,
e->scheduler); 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( struct pragma_packet_builder* ctxt = labcomm_memory_alloc(
e->memory, e->memory,
1, 1,
sizeof(struct pragma_packet_builder)); sizeof(struct pragma_packet_builder));
if(ctxt){ if(ctxt){
ctxt->pragma_type=pragma_type; ctxt->pragma_type=ptype;
ctxt->parent=e; ctxt->parent=e;
} }
mdt->context_type = LABCOMM_PRAGMA; pb->context_type = LABCOMM_PRAGMA;
mdt->context = ctxt; pb->context = ctxt;
return mdt; return pb;
} }
//HERE BE DRAGONS! Copied from decoder.c //HERE BE DRAGONS! Copied from decoder.c
...@@ -196,6 +205,8 @@ int labcomm_pragma_send(struct labcomm_encoder* e) ...@@ -196,6 +205,8 @@ int labcomm_pragma_send(struct labcomm_encoder* e)
err = p->writer->error; err = p->writer->error;
} }
free_encoder: 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_memory_free(e->memory, 1, ctx);
labcomm_encoder_free(e); labcomm_encoder_free(e);
return err; return err;
......
Supports Markdown
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