From 91713054f830643d2789994786fc291e55d6c7e7 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Mon, 1 Jun 2015 21:31:37 -0400 Subject: [PATCH 1/4] fix a couple of small memory leaks --- v/unix.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/v/unix.c b/v/unix.c index 61e3807eae..9a3cbca24a 100644 --- a/v/unix.c +++ b/v/unix.c @@ -334,6 +334,7 @@ _unix_file_done(uv_handle_t* was_u) u3_ufil* fil_u = (void*) was_u; // uL(fprintf(uH, "file: dun: %s\n", fil_u->pax_c)); + free(fil_u->pot_c); free(fil_u->pax_c); free(fil_u); } @@ -393,6 +394,7 @@ _unix_dir_done(uv_handle_t* was_u) dir_u->fil_u = nex_u; } + free(dir_u->pot_c); free(dir_u->pax_c); free(dir_u); } @@ -1117,15 +1119,15 @@ _unix_mkpath(const char *s) goto out; if ((up = strdup(r)) == NULL) - exit(1); + c3_assert(0); _unix_mkpath(up); _unix_mkdir(path); + free(r); + free(up); out: - if (up != NULL) - free(up); free(q); free(path); } From 529301335b208a5a053f2fccc90f508fdf2d9145 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Tue, 2 Jun 2015 16:40:53 -0400 Subject: [PATCH 2/4] attempting to fix goning problem --- v/unix.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/v/unix.c b/v/unix.c index 5e252ffad5..6edacc58d0 100644 --- a/v/unix.c +++ b/v/unix.c @@ -714,7 +714,7 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) } else { u3_noun elo; - elo = u3nt(u3_nul, woz, u3k(u3t(u3t(ole)))); + elo = u3nq(u3_nul, woz, u3_nul, u3k(u3t(u3t(ole)))); u3z(ole); ole = elo; @@ -729,7 +729,8 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) if ( u3_none == ole || u3_nul == ole ) { - ole = u3nt(u3_nul, + ole = u3nq(u3_nul, + u3_nul, u3_nul, u3kdb_put(u3_nul, u3k(har), @@ -737,7 +738,7 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) } else { u3_noun oor, elo; - u3_noun roo = u3t(u3t(ole)); + u3_noun roo = u3t(u3t(u3t(ole))); u3_weak tup = u3kdb_get(u3k(roo), u3k(har)); if ( u3_none == tup ) { @@ -745,13 +746,13 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) } else { u3_noun upt; - upt = u3nt(u3_nul, woz, u3k(u3t(tup))); + upt = u3nq(u3_nul, woz, u3_nul, u3k(u3t(tup))); u3z(tup); tup = upt; } oor = u3kdb_put(u3k(roo), u3k(har), tup); - elo = u3nt(u3_nul, u3k(u3h(u3t(ole))), oor); + elo = u3nq(u3_nul, u3k(u3h(u3t(ole))), u3_nul, oor); u3z(ole); ole = elo; } @@ -812,7 +813,7 @@ _unix_dir_khan(u3_udir* dir_u) u3nt(u3_nul, u3_nul, baw)); pam = _unix_dir_khan_file(pam, wib, wol); } - return u3nt(u3_nul, u3_nul, pam); + return u3nq(u3_nul, u3_nul, u3_nul, pam); } /* _find_mug(): find a noun with a given mug. retain. DELETEME From bdd7f6b171f5c1dd5910082cc16dc51e7dbc1da6 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Tue, 2 Jun 2015 20:13:10 -0400 Subject: [PATCH 3/4] better fix --- v/unix.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/v/unix.c b/v/unix.c index 6edacc58d0..f2706426af 100644 --- a/v/unix.c +++ b/v/unix.c @@ -334,7 +334,7 @@ _unix_file_done(uv_handle_t* was_u) u3_ufil* fil_u = (void*) was_u; // uL(fprintf(uH, "file: dun: %s\n", fil_u->pax_c)); - free(fil_u->pot_c); + // free(fil_u->pot_c); XXX free(fil_u->pax_c); free(fil_u); } @@ -394,7 +394,7 @@ _unix_dir_done(uv_handle_t* was_u) dir_u->fil_u = nex_u; } - free(dir_u->pot_c); + // free(dir_u->pot_c); XXX free(dir_u->pax_c); free(dir_u); } @@ -708,13 +708,16 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) if ( c3n == u3du(wib) ) { ole = u3kdb_get(u3k(pam), u3k(wib)); - if ( u3_none == ole || - u3_nul == ole ) { + if ( u3_none == ole ) { + ole = u3nq(u3_nul, woz, u3_nul, u3_nul); + } + else if ( u3_nul == ole ) { ole = u3nt(u3_nul, woz, u3_nul); - } else { + } + else { u3_noun elo; - elo = u3nq(u3_nul, woz, u3_nul, u3k(u3t(u3t(ole)))); + elo = u3nt(u3_nul, woz, u3k(u3t(u3t(ole)))); u3z(ole); ole = elo; @@ -727,14 +730,16 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) ole = u3kdb_get(u3k(pam), u3k(fid)); - if ( u3_none == ole || - u3_nul == ole ) { + if ( u3_none == ole ) { ole = u3nq(u3_nul, u3_nul, u3_nul, u3kdb_put(u3_nul, u3k(har), - u3nt(u3_nul, woz, u3_nul))); + u3nq(u3_nul, woz, u3_nul, u3_nul))); + } + else if ( u3_nul == ole ) { + // XX } else { u3_noun oor, elo; @@ -767,15 +772,21 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) static u3_noun _unix_dir_khan(u3_udir* dir_u) { - //if ( c3y == dir_u->dry ) { - // return u3_nul; - //} + if ( c3y == dir_u->dry ) { + return u3_nul; + } u3_udir* dis_u; u3_ufil* fil_u; u3_noun pam = u3_nul; for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) { + for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { + if ( 0 == strncmp(dis_u->pax_c, fil_u->pax_c, strlen(dis_u->pax_c)) ) { + dis_u->dry = c3n; + break; + } + } u3_noun pre = _unix_dir_name(dis_u); u3_noun kan = _unix_dir_khan(dis_u); From 11c36dad35b4bc86bf3569c2fd7290ec7e0d6108 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Tue, 2 Jun 2015 20:35:09 -0400 Subject: [PATCH 4/4] add sanity assert --- v/unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v/unix.c b/v/unix.c index f2706426af..ea6b603087 100644 --- a/v/unix.c +++ b/v/unix.c @@ -739,7 +739,7 @@ _unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun woz) u3nq(u3_nul, woz, u3_nul, u3_nul))); } else if ( u3_nul == ole ) { - // XX + c3_assert(!"impossible because of the strncmp check in _unix_dir_khan"); } else { u3_noun oor, elo;