diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 7ae2d9016..90e79be2d 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -127,6 +127,18 @@ static void __ng_buffer_free(void *p) { obj_put_o(ngbuf->ref); } +struct ng_buffer *ng_buffer_new(struct obj *ref) { + struct ng_buffer *ngbuf = obj_alloc0("ng_buffer", sizeof(*ngbuf), __ng_buffer_free); + if (ref) + ngbuf->ref = obj_get_o(ref); // hold until we're done + + int ret = bencode_buffer_init(&ngbuf->buffer); + assert(ret == 0); + (void) ret; + + return ngbuf; +} + int control_ng_process(str *buf, const endpoint_t *sin, char *addr, void (*cb)(str *, str *, const endpoint_t *, void *), void *p1, struct obj *ref) { @@ -147,14 +159,8 @@ int control_ng_process(str *buf, const endpoint_t *sin, char *addr, return funcret; } - // init decode buffer object - ngbuf = obj_alloc0("ng_buffer", sizeof(*ngbuf), __ng_buffer_free); - if (ref) - ngbuf->ref = obj_get_o(ref); // hold until we're done + ngbuf = ng_buffer_new(ref); - int ret = bencode_buffer_init(&ngbuf->buffer); - assert(ret == 0); - (void) ret; resp = bencode_dictionary(&ngbuf->buffer); assert(resp != NULL); diff --git a/include/control_ng.h b/include/control_ng.h index f6883897a..d3deecdd9 100644 --- a/include/control_ng.h +++ b/include/control_ng.h @@ -76,6 +76,8 @@ void control_ng_cleanup(void); int control_ng_process(str *buf, const endpoint_t *sin, char *addr, void (*cb)(str *, str *, const endpoint_t *, void *), void *p1, struct obj *); +struct ng_buffer *ng_buffer_new(struct obj *ref); + INLINE void ng_buffer_release(struct ng_buffer *ngbuf) { obj_put(ngbuf); }