@@ -229,11 +229,17 @@ const char *hyper_version(void);
229
229
Create a new "empty" body.
230
230
231
231
If not configured, this body acts as an empty payload.
232
+
233
+ To avoid a memory leak, the body must eventually be consumed by
234
+ `hyper_body_free`, `hyper_body_foreach`, or `hyper_request_set_body`.
232
235
*/
233
236
struct hyper_body * hyper_body_new (void );
234
237
235
238
/*
236
- Free a `hyper_body *`.
239
+ Free a body.
240
+
241
+ This should only be used if the request isn't consumed by
242
+ `hyper_body_foreach` or `hyper_request_set_body`.
237
243
*/
238
244
void hyper_body_free (struct hyper_body * body );
239
245
@@ -246,6 +252,10 @@ void hyper_body_free(struct hyper_body *body);
246
252
- `HYPER_TASK_ERROR`: An error retrieving the data.
247
253
- `HYPER_TASK_EMPTY`: The body has finished streaming data.
248
254
255
+ To avoid a memory leak, the task must eventually be consumed by
256
+ `hyper_task_free`, or taken ownership of by `hyper_executor_push`
257
+ without subsequently being given back by `hyper_executor_poll`.
258
+
249
259
This does not consume the `hyper_body *`, so it may be used to again.
250
260
However, it MUST NOT be used or freed until the related task completes.
251
261
*/
@@ -255,6 +265,10 @@ struct hyper_task *hyper_body_data(struct hyper_body *body);
255
265
Return a task that will poll the body and execute the callback with each
256
266
body chunk that is received.
257
267
268
+ To avoid a memory leak, the task must eventually be consumed by
269
+ `hyper_task_free`, or taken ownership of by `hyper_executor_push`
270
+ without subsequently being given back by `hyper_executor_poll`.
271
+
258
272
The `hyper_buf` pointer is only a borrowed reference, it cannot live outside
259
273
the execution of the callback. You must make a copy to retain it.
260
274
@@ -299,7 +313,10 @@ void hyper_body_set_data_func(struct hyper_body *body, hyper_body_data_callback
299
313
Create a new `hyper_buf *` by copying the provided bytes.
300
314
301
315
This makes an owned copy of the bytes, so the `buf` argument can be
302
- freed or changed afterwards.
316
+ freed (with `hyper_buf_free`) or changed afterwards.
317
+
318
+ To avoid a memory leak, the copy must eventually be consumed by
319
+ `hyper_buf_free`.
303
320
304
321
This returns `NULL` if allocating a new buffer fails.
305
322
*/
@@ -323,6 +340,8 @@ size_t hyper_buf_len(const struct hyper_buf *buf);
323
340
324
341
/*
325
342
Free this buffer.
343
+
344
+ This should be used for any buffer once it is no longer needed.
326
345
*/
327
346
void hyper_buf_free (struct hyper_buf * buf );
328
347
@@ -331,28 +350,45 @@ void hyper_buf_free(struct hyper_buf *buf);
331
350
and options.
332
351
333
352
Both the `io` and the `options` are consumed in this function call.
353
+ They should not be used or freed afterwards.
354
+
355
+ The returned task must be polled with an executor until the handshake
356
+ completes, at which point the value can be taken.
334
357
335
- The returned `hyper_task *` must be polled with an executor until the
336
- handshake completes, at which point the value can be taken.
358
+ To avoid a memory leak, the task must eventually be consumed by
359
+ `hyper_task_free`, or taken ownership of by `hyper_executor_push`
360
+ without subsequently being given back by `hyper_executor_poll`.
337
361
*/
338
362
struct hyper_task * hyper_clientconn_handshake (struct hyper_io * io ,
339
363
struct hyper_clientconn_options * options );
340
364
341
365
/*
342
366
Send a request on the client connection.
343
367
368
+ This consumes the request. You should not use or free the request
369
+ afterwards.
370
+
344
371
Returns a task that needs to be polled until it is ready. When ready, the
345
372
task yields a `hyper_response *`.
373
+
374
+ To avoid a memory leak, the task must eventually be consumed by
375
+ `hyper_task_free`, or taken ownership of by `hyper_executor_push`
376
+ without subsequently being given back by `hyper_executor_poll`.
346
377
*/
347
378
struct hyper_task * hyper_clientconn_send (struct hyper_clientconn * conn , struct hyper_request * req );
348
379
349
380
/*
350
381
Free a `hyper_clientconn *`.
382
+
383
+ This should be used for any connection once it is no longer needed.
351
384
*/
352
385
void hyper_clientconn_free (struct hyper_clientconn * conn );
353
386
354
387
/*
355
388
Creates a new set of HTTP clientconn options to be used in a handshake.
389
+
390
+ To avoid a memory leak, the options must eventually be consumed by
391
+ `hyper_clientconn_options_free` or `hyper_clientconn_handshake`.
356
392
*/
357
393
struct hyper_clientconn_options * hyper_clientconn_options_new (void );
358
394
@@ -373,7 +409,10 @@ void hyper_clientconn_options_set_preserve_header_order(struct hyper_clientconn_
373
409
int enabled );
374
410
375
411
/*
376
- Free a `hyper_clientconn_options *`.
412
+ Free a set of HTTP clientconn options.
413
+
414
+ This should only be used if the options aren't consumed by
415
+ `hyper_clientconn_handshake`.
377
416
*/
378
417
void hyper_clientconn_options_free (struct hyper_clientconn_options * opts );
379
418
@@ -404,6 +443,8 @@ enum hyper_code hyper_clientconn_options_http1_allow_multiline_headers(struct hy
404
443
405
444
/*
406
445
Frees a `hyper_error`.
446
+
447
+ This should be used for any error once it is no longer needed.
407
448
*/
408
449
void hyper_error_free (struct hyper_error * err );
409
450
@@ -424,11 +465,17 @@ size_t hyper_error_print(const struct hyper_error *err, uint8_t *dst, size_t dst
424
465
425
466
/*
426
467
Construct a new HTTP request.
468
+
469
+ To avoid a memory leak, the request must eventually be consumed by
470
+ `hyper_request_free` or `hyper_clientconn_send`.
427
471
*/
428
472
struct hyper_request * hyper_request_new (void );
429
473
430
474
/*
431
- Free an HTTP request if not going to send it on a client.
475
+ Free an HTTP request.
476
+
477
+ This should only be used if the request isn't consumed by
478
+ `hyper_clientconn_send`.
432
479
*/
433
480
void hyper_request_free (struct hyper_request * req );
434
481
@@ -526,7 +573,9 @@ enum hyper_code hyper_request_on_informational(struct hyper_request *req,
526
573
void * data );
527
574
528
575
/*
529
- Free an HTTP response after using it.
576
+ Free an HTTP response.
577
+
578
+ This should be used for any response once it is no longer needed.
530
579
*/
531
580
void hyper_response_free (struct hyper_response * resp );
532
581
@@ -581,6 +630,9 @@ struct hyper_headers *hyper_response_headers(struct hyper_response *resp);
581
630
Take ownership of the body of this response.
582
631
583
632
It is safe to free the response even after taking ownership of its body.
633
+
634
+ To avoid a memory leak, the body must eventually be consumed by
635
+ `hyper_body_free`, `hyper_body_foreach`, or `hyper_request_set_body`.
584
636
*/
585
637
struct hyper_body * hyper_response_body (struct hyper_response * resp );
586
638
@@ -624,14 +676,17 @@ enum hyper_code hyper_headers_add(struct hyper_headers *headers,
624
676
625
677
The read and write functions of this transport should be set with
626
678
`hyper_io_set_read` and `hyper_io_set_write`.
679
+
680
+ To avoid a memory leak, the IO handle must eventually be consumed by
681
+ `hyper_io_free` or `hyper_clientconn_handshake`.
627
682
*/
628
683
struct hyper_io * hyper_io_new (void );
629
684
630
685
/*
631
- Free an unused `hyper_io *` .
686
+ Free an IO handle .
632
687
633
- This is typically only useful if you aren 't going to pass ownership
634
- of the IO handle to hyper, such as with `hyper_clientconn_handshake() `.
688
+ This should only be used if the request isn 't consumed by
689
+ `hyper_clientconn_handshake`.
635
690
*/
636
691
void hyper_io_free (struct hyper_io * io );
637
692
@@ -681,18 +736,23 @@ void hyper_io_set_write(struct hyper_io *io, hyper_io_write_callback func);
681
736
682
737
/*
683
738
Creates a new task executor.
739
+
740
+ To avoid a memory leak, the executor must eventually be consumed by
741
+ `hyper_executor_free`.
684
742
*/
685
743
const struct hyper_executor * hyper_executor_new (void );
686
744
687
745
/*
688
746
Frees an executor and any incomplete tasks still part of it.
747
+
748
+ This should be used for any executor once it is no longer needed.
689
749
*/
690
750
void hyper_executor_free (const struct hyper_executor * exec );
691
751
692
752
/*
693
753
Push a task onto the executor.
694
754
695
- The executor takes ownership of the task, it should not be accessed
755
+ The executor takes ownership of the task, which should not be accessed
696
756
again unless returned back to the user with `hyper_executor_poll`.
697
757
*/
698
758
enum hyper_code hyper_executor_push (const struct hyper_executor * exec , struct hyper_task * task );
@@ -703,12 +763,20 @@ enum hyper_code hyper_executor_push(const struct hyper_executor *exec, struct hy
703
763
704
764
If ready, returns a task from the executor that has completed.
705
765
766
+ To avoid a memory leak, the task must eventually be consumed by
767
+ `hyper_task_free`, or taken ownership of by `hyper_executor_push`
768
+ without subsequently being given back by `hyper_executor_poll`.
769
+
706
770
If there are no ready tasks, this returns `NULL`.
707
771
*/
708
772
struct hyper_task * hyper_executor_poll (const struct hyper_executor * exec );
709
773
710
774
/*
711
775
Free a task.
776
+
777
+ This should only be used if the task isn't consumed by
778
+ `hyper_clientconn_handshake` or taken ownership of by
779
+ `hyper_executor_push`.
712
780
*/
713
781
void hyper_task_free (struct hyper_task * task );
714
782
@@ -719,6 +787,11 @@ void hyper_task_free(struct hyper_task *task);
719
787
this task.
720
788
721
789
Use `hyper_task_type` to determine the type of the `void *` return value.
790
+
791
+ To avoid a memory leak, a non-empty return value must eventually be
792
+ consumed by a function appropriate for its type, one of
793
+ `hyper_error_free`, `hyper_clientconn_free`, `hyper_response_free`, or
794
+ `hyper_buf_free`.
722
795
*/
723
796
void * hyper_task_value (struct hyper_task * task );
724
797
@@ -742,11 +815,17 @@ void *hyper_task_userdata(struct hyper_task *task);
742
815
743
816
/*
744
817
Copies a waker out of the task context.
818
+
819
+ To avoid a memory leak, the waker must eventually be consumed by
820
+ `hyper_waker_free` or `hyper_waker_wake`.
745
821
*/
746
822
struct hyper_waker * hyper_context_waker (struct hyper_context * cx );
747
823
748
824
/*
749
- Free a waker that hasn't been woken.
825
+ Free a waker.
826
+
827
+ This should only be used if the request isn't consumed by
828
+ `hyper_waker_wake`.
750
829
*/
751
830
void hyper_waker_free (struct hyper_waker * waker );
752
831
0 commit comments