From 8de9a059cef465f84ed554e3f6277c7174fc7751 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 28 Sep 2018 21:40:13 -0400 Subject: [PATCH 1/5] fixes leak in _http_serv_start_all by removing calls to u3_lo_open and u3_lo_shut --- vere/http.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vere/http.c b/vere/http.c index ddd509a80..c3ee073a7 100644 --- a/vere/http.c +++ b/vere/http.c @@ -1383,7 +1383,8 @@ _http_serv_start_all(void) c3_assert( 0 != for_u ); - u3_lo_open(); + // disabled, as this causes a memory leak + // u3_lo_open(); // if the SSL_CTX existed, it'll be freed with the servers u3_Host.tls_u = 0; @@ -1444,7 +1445,8 @@ _http_serv_start_all(void) _http_write_ports_file(u3_Host.dir_c); _http_form_free(); - u3_lo_shut(c3y); + // disabled, see above + // u3_lo_shut(c3y); } /* _http_serv_restart(): gracefully shutdown, then start servers. From 34570e428e209946a75d5fce3e4ef1566d02d64d Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 28 Sep 2018 21:41:48 -0400 Subject: [PATCH 2/5] fixes leak in proxy when networking is disabled --- vere/http.c | 1 + 1 file changed, 1 insertion(+) diff --git a/vere/http.c b/vere/http.c index c3ee073a7..87596fc4e 100644 --- a/vere/http.c +++ b/vere/http.c @@ -2861,6 +2861,7 @@ u3_http_ef_that(u3_noun tat) if ( c3n == u3_Host.ops_u.net ) { cli_u->ipf_w = INADDR_LOOPBACK; _proxy_ward_connect(cli_u); + u3z(tat); return; } From 8affdf44ea86049cb3d4107c3d274ba2c16e9170 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 28 Sep 2018 21:44:04 -0400 Subject: [PATCH 3/5] refactors http card validation in u3_http_ef_that and u3_http_ef_form --- vere/http.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/vere/http.c b/vere/http.c index 87596fc4e..2741ad1d9 100644 --- a/vere/http.c +++ b/vere/http.c @@ -1501,15 +1501,26 @@ _http_form_free(void) void u3_http_ef_form(u3_noun fig) { - // XX validate / test axes? - u3_noun sec = u3h(fig); - u3_noun lob = u3t(fig); + u3_noun sec, pro, log, red; + + if ( (c3n == u3r_qual(fig, &sec, &pro, &log, &red) ) || + // confirm sec is a valid (unit ^) + !( u3_nul == sec || ( c3y == u3du(sec) && + c3y == u3du(u3t(sec)) && + u3_nul == u3h(sec) ) ) || + // confirm valid flags ("loobeans") + !( c3y == pro || c3n == pro ) || + !( c3y == log || c3n == log ) || + !( c3y == red || c3n == red ) ) { + uL(fprintf(uH, "http: form: invalid card\n")); + u3z(fig); + return; + } u3_form* for_u = c3_malloc(sizeof(*for_u)); - - for_u->pro = (c3_o)u3h(lob); - for_u->log = (c3_o)u3h(u3t(lob)); - for_u->red = (c3_o)u3t(u3t(lob)); + for_u->pro = (c3_o)pro; + for_u->log = (c3_o)log; + for_u->red = (c3_o)red; if ( u3_nul != sec ) { u3_noun key = u3h(u3t(sec)); @@ -2813,15 +2824,13 @@ _proxy_serv_start(u3_prox* lis_u) void u3_http_ef_that(u3_noun tat) { - u3_noun sip = u3h(tat); - u3_noun por = u3h(u3t(tat)); - u3_noun sec = u3h(u3t(u3t(tat))); - u3_noun non = u3t(u3t(u3t(tat))); + u3_noun sip, por, sec, non; - if( c3n == u3ud(sip) || - c3n == u3a_is_cat(por) || - !( c3y == sec || c3n == sec ) || - c3n == u3ud(non) ) { + if ( ( c3n == u3r_qual(tat, &sip, &por, &sec, &non) ) || + ( c3n == u3ud(sip) ) || + ( c3n == u3a_is_cat(por) ) || + !( c3y == sec || c3n == sec ) || + ( c3n == u3ud(non) ) ) { uL(fprintf(uH, "http: that: invalid card\n")); u3z(tat); return; From 9302d4708c97fbbde8751a5c3e14795c693fc675 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 28 Sep 2018 22:52:19 -0400 Subject: [PATCH 4/5] adds meson option (-Dgc=true) to set U3_MEMORY_DEBUG --- include/config.h.in | 2 ++ include/noun/allocate.h | 6 ------ meson.build | 1 + meson_options.txt | 2 ++ 4 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 meson_options.txt diff --git a/include/config.h.in b/include/config.h.in index 66f778309..d2d7baff8 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -10,4 +10,6 @@ #mesondefine U3_OS_ENDIAN_little #mesondefine U3_OS_ENDIAN_big +#mesondefine U3_MEMORY_DEBUG + #endif /*CONFIG_H*/ diff --git a/include/noun/allocate.h b/include/noun/allocate.h index 075b12d2f..efce7ed97 100644 --- a/include/noun/allocate.h +++ b/include/noun/allocate.h @@ -2,12 +2,6 @@ ** ** This file is in the public domain. */ - /** Options. - **/ - /* U3_MEMORY_DEBUG: add debugging information to heap. Breaks image. - */ -# undef U3_MEMORY_DEBUG - /** Constants. **/ /* u3a_bits: number of bits in word-addressed pointer. 29 == 2GB. diff --git a/meson.build b/meson.build index 2fc9b1453..d8c17808c 100644 --- a/meson.build +++ b/meson.build @@ -264,6 +264,7 @@ incdir = include_directories('include/') conf_data = configuration_data() conf_data.set('URBIT_VERSION', '"0.6.0"') +conf_data.set('U3_MEMORY_DEBUG', get_option('gc')) osdet = build_machine.system() os_c_flags = ['-funsigned-char','-ffast-math'] diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..4f9bb057a --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,2 @@ +option('gc', type : 'boolean', value : false, + description : 'Add debugging information to heap. Run with -g. Breaks image.') From 7a2705bb6dd1583150666103ea8a706b49bceb9f Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 28 Sep 2018 22:57:31 -0400 Subject: [PATCH 5/5] adds meson option (-Dprof=true) to set U3_CPU_DEBUG --- include/config.h.in | 1 + include/noun/trace.h | 6 ------ meson.build | 1 + meson_options.txt | 2 ++ 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/config.h.in b/include/config.h.in index d2d7baff8..e8063e87e 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -11,5 +11,6 @@ #mesondefine U3_OS_ENDIAN_big #mesondefine U3_MEMORY_DEBUG +#mesondefine U3_CPU_DEBUG #endif /*CONFIG_H*/ diff --git a/include/noun/trace.h b/include/noun/trace.h index 5b847f521..838ce835f 100644 --- a/include/noun/trace.h +++ b/include/noun/trace.h @@ -2,12 +2,6 @@ ** ** This file is in the public domain. */ - /** Options. - **/ - /* U3_CPU_DEBUG: activate profiling. - */ -# undef U3_CPU_DEBUG - /** Data structures. **/ /* u3t_trace: fast execution flags. diff --git a/meson.build b/meson.build index d8c17808c..4cefeff2f 100644 --- a/meson.build +++ b/meson.build @@ -265,6 +265,7 @@ incdir = include_directories('include/') conf_data = configuration_data() conf_data.set('URBIT_VERSION', '"0.6.0"') conf_data.set('U3_MEMORY_DEBUG', get_option('gc')) +conf_data.set('U3_CPU_DEBUG', get_option('prof')) osdet = build_machine.system() os_c_flags = ['-funsigned-char','-ffast-math'] diff --git a/meson_options.txt b/meson_options.txt index 4f9bb057a..a4dd84385 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,4 @@ option('gc', type : 'boolean', value : false, description : 'Add debugging information to heap. Run with -g. Breaks image.') +option('prof', type : 'boolean', value : false, + description : 'Activate profiling. Run with -P.')