9front - general discussion about 9front
 help / color / mirror / Atom feed
From: "Igor Boehm" <boehm.igor@gmail.com>
To: 9front@9front.org
Cc: boehm.igor@gmail.com
Subject: [9front] cmd/sort: fix resource leak (patch)
Date: Tue, 29 Dec 2020 15:28:20 +0100	[thread overview]
Message-ID: <3BA32B1BEC14B099376DC7279062EB92@gmail.com> (raw)

There is a small resource leak in cmd/sort.c:/^dofile.

Here is the code with some hopefully explanatory annotations (one
liner patch is below):

<snip>
void
dofile(Biobuf *b)
{
	Line *l, *ol;
	int n;

	if(args.cflag) {
		if((ol = newline(b)) == nil)
			return;
		for(;;) {
			if((l = newline(b)) == nil)
				break;
^^^^^^^^^^^^^^^^^^^^^^
Break out of for leakes 'ol' 				
				
			n = kcmp(ol->key, l->key);
			if(n > 0 || (n == 0 && args.uflag)) {
				fprint(2, "sort: -c file not in sort\n"); /**/
				done("order");
			}
			free(ol->key);
			free(ol);
			ol = l;
^^^^^^^^^^^^^^^^^^^^^^
Assign 'l' to 'ol' and again break out of for would leak that		
		}
		return;
^^^^^^^^^^^^^^^
There should be a 'free(ol);' before this 'return'
	}
</snip>

Here is the one line fix as an inline diff:

diff -r 4c6206d69abb sys/src/cmd/sort.c
--- a/sys/src/cmd/sort.c	Mon Dec 28 21:21:22 2020 +0100
+++ b/sys/src/cmd/sort.c	Tue Dec 29 15:11:29 2020 +0100
@@ -209,6 +209,7 @@
 			free(ol);
 			ol = l;
 		}
+		free(ol);
 		return;
 	}
 


             reply	other threads:[~2020-12-29 14:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-29 14:28 Igor Boehm [this message]
2021-01-01 17:42 ` ori
2021-01-01 19:32   ` Igor Boehm
2021-01-01 19:49     ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BA32B1BEC14B099376DC7279062EB92@gmail.com \
    --to=boehm.igor@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).