From e14f05ce30891fec35a6b5489c60887d97f78a39 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 25 May 2020 00:05:14 -0400 Subject: minor memory leakage multiple twobytes returns require a single array that isn't on the heap but automatically allocated. removed printf's and freed some "" lines. --- badroff.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/badroff.c b/badroff.c index 7134261..7bdb3e7 100644 --- a/badroff.c +++ b/badroff.c @@ -145,21 +145,21 @@ llnode* accumlines(size_t* ct){ // returns tail of linked list (*ct) = 0; while (!endgroup){ char* ln = line(); + if (!ln[0]) { // ln == "" + free(ln); + break; + } size_t len = strlen(ln); char* next; while ( (next = breakstr(ln, &len))){ - printf("line %s\n",ln); tail->next = appendll(tail, ln); tail = tail->next; (*ct)++; - printf("added\n"); ln = next; }; - printf("loop\n"); } tail->next = head->next; // loop linked list free(head); - printf("here\n"); endgroup = false; // prevents false positive on next run return tail; } @@ -332,7 +332,9 @@ char* line(void){ size_t sz; if ( (sz = fillbuf(2)) == 0) return ""; - char* twobytes = peekstrbuf(inbuf, 0, 2); // .., .\n, or ^.? + char twobytes[3]; + char* peek = peekstrbuf(inbuf, 0, 2); // .., .\n, or ^.? + memcpy(twobytes, peek, 3); free(peek); if (sz == 1 || twobytes[1] == '\n') return norm(); if (twobytes[0] == '.') popchrbuf(inbuf); char* out; @@ -343,7 +345,6 @@ char* line(void){ } else { out = norm(); } - free(twobytes); nbspsub(out); return out; } -- cgit