@@ -183,6 +183,13 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon
183183 HTTPHdr copy1;
184184 HTTPHdr copy2;
185185
186+ ts::PostScript cleanup ([&]() -> void {
187+ req_hdr.destroy ();
188+ resp_hdr.destroy ();
189+ copy1.destroy ();
190+ copy2.destroy ();
191+ });
192+
186193 HTTPParser parser;
187194 const char *start;
188195 const char *end;
@@ -207,7 +214,6 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon
207214
208215 if (err == ParseResult::ERROR) {
209216 std::printf (" FAILED: (test #%d) parse error parsing request hdr\n " , testnum);
210- req_hdr.destroy ();
211217 return (0 );
212218 }
213219 http_parser_clear (&parser);
@@ -230,8 +236,6 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon
230236
231237 if (err == ParseResult::ERROR) {
232238 printf (" FAILED: (test #%d) parse error parsing response hdr\n " , testnum);
233- req_hdr.destroy ();
234- resp_hdr.destroy ();
235239 return (0 );
236240 }
237241
@@ -263,16 +267,8 @@ test_http_hdr_copy_over_aux(int testnum, const char *request, const char *respon
263267
264268 copy2.copy (&req_hdr);
265269 comp_str = comp_http_hdr (&req_hdr, ©2);
266- if (comp_str) {
267- goto done;
268- }
269270
270271done:
271- req_hdr.destroy ();
272- resp_hdr.destroy ();
273- copy1.destroy ();
274- copy2.destroy ();
275-
276272 if (comp_str) {
277273 printf (" FAILED: (test #%d) copy & compare: %s\n " , testnum, comp_str);
278274 printf (" REQ:\n [%.*s]\n " , static_cast <int >(strlen (request)), request);
@@ -382,10 +378,16 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
382378{
383379 ParseResult err;
384380 HTTPHdr hdr;
381+ HTTPHdr new_hdr;
385382 HTTPParser parser;
386383 const char *start;
387384 const char *end;
388385
386+ ts::PostScript cleanup ([&]() -> void {
387+ hdr.destroy ();
388+ new_hdr.destroy ();
389+ });
390+
389391 char prt_buf[2048 ];
390392 int prt_bufsize = sizeof (prt_buf);
391393 int prt_bufindex, prt_dumpoffset, prt_ret;
@@ -415,12 +417,11 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
415417
416418 if (err == ParseResult::ERROR) {
417419 std::printf (" FAILED: (test #%d) parse error parsing request hdr\n " , testnum);
418- hdr.destroy ();
419420 return (0 );
420421 }
421422
422423 /* ** (2) copy the request header ***/
423- HTTPHdr new_hdr, marshal_hdr;
424+ HTTPHdr marshal_hdr;
424425 TestRefCountObj ref;
425426
426427 // Pretend to pin this object with a refcount.
@@ -442,9 +443,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
442443
443444 if ((prt_ret != 1 ) || (cpy_ret != 1 )) {
444445 std::printf (" FAILED: (test #%d) couldn't print req hdr or copy --- prt_ret=%d, cpy_ret=%d\n " , testnum, prt_ret, cpy_ret);
445- hdr.destroy ();
446- new_hdr.destroy ();
447-
448446 return (0 );
449447 }
450448
@@ -456,9 +454,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
456454 std::printf (" TARGET :\n [%.*s]\n " , static_cast <int >(strlen (request_tgt)), request_tgt);
457455 std::printf (" PRT_BUFF:\n [%.*s]\n " , prt_bufindex, prt_buf);
458456 std::printf (" CPY_BUFF:\n [%.*s]\n " , cpy_bufindex, cpy_buf);
459- hdr.destroy ();
460- new_hdr.destroy ();
461-
462457 return (0 );
463458 }
464459
@@ -469,9 +464,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
469464 std::printf (" TARGET :\n [%.*s]\n " , static_cast <int >(strlen (request_tgt)), request_tgt);
470465 std::printf (" PRT_BUFF:\n [%.*s]\n " , prt_bufindex, prt_buf);
471466 std::printf (" CPY_BUFF:\n [%.*s]\n " , cpy_bufindex, cpy_buf);
472- hdr.destroy ();
473- new_hdr.destroy ();
474-
475467 return (0 );
476468 }
477469
@@ -496,7 +488,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
496488
497489 if (err == ParseResult::ERROR) {
498490 std::printf (" FAILED: (test #%d) parse error parsing response hdr\n " , testnum);
499- hdr.destroy ();
500491 return (0 );
501492 }
502493
@@ -515,8 +506,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
515506
516507 if ((prt_ret != 1 ) || (cpy_ret != 1 )) {
517508 std::printf (" FAILED: (test #%d) couldn't print rsp hdr or copy --- prt_ret=%d, cpy_ret=%d\n " , testnum, prt_ret, cpy_ret);
518- hdr.destroy ();
519- new_hdr.destroy ();
520509 return (0 );
521510 }
522511
@@ -527,8 +516,6 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
527516 std::printf (" TARGET :\n [%.*s]\n " , static_cast <int >(strlen (response_tgt)), response_tgt);
528517 std::printf (" PRT_BUFF:\n [%.*s]\n " , prt_bufindex, prt_buf);
529518 std::printf (" CPY_BUFF:\n [%.*s]\n " , cpy_bufindex, cpy_buf);
530- hdr.destroy ();
531- new_hdr.destroy ();
532519 return (0 );
533520 }
534521
@@ -539,14 +526,9 @@ test_http_hdr_print_and_copy_aux(int testnum, const char *request, const char *r
539526 std::printf (" TARGET :\n [%.*s]\n " , static_cast <int >(strlen (response_tgt)), response_tgt);
540527 std::printf (" PRT_BUFF:\n [%.*s]\n " , prt_bufindex, prt_buf);
541528 std::printf (" CPY_BUFF:\n [%.*s]\n " , cpy_bufindex, cpy_buf);
542- hdr.destroy ();
543- new_hdr.destroy ();
544529 return (0 );
545530 }
546531
547- hdr.destroy ();
548- new_hdr.destroy ();
549-
550532 if (test_http_hdr_copy_over_aux (testnum, request, response) == 0 ) {
551533 return 0 ;
552534 }
0 commit comments