diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-05-25 00:05:14 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-05-25 00:06:07 -0400 |
commit | e14f05ce30891fec35a6b5489c60887d97f78a39 (patch) | |
tree | b3f6e29c391ff661575b743a4093f19ac72d7a19 | |
parent | 0d99da583acc79163057561e4a2deeae8a5ae083 (diff) |
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.
-rw-r--r-- | badroff.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -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; } |