public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Prikryl <zprikryl@redhat.com>
To: xfs@oss.sgi.com
Subject: libattr - severe memory leaks from attr_copy_file()
Date: Tue, 17 Feb 2009 12:50:18 +0100	[thread overview]
Message-ID: <499AA47A.2050106@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 191 bytes --]

Hello,
libattr's function attr_copy_file() seems to be producing severe memory leaks.
I'm sending a patch which removes sources of leaks.

Regards.

-- 
Zdenek Prikryl <zprikryl@redhat.com>


[-- Attachment #2: attr-2.4.32-leak.patch --]
[-- Type: text/plain, Size: 1083 bytes --]

diff -up attr-2.4.43/libattr/attr_copy_action.c.leak attr-2.4.43/libattr/attr_copy_action.c
--- attr-2.4.43/libattr/attr_copy_action.c.leak	2008-06-30 07:22:50.000000000 +0200
+++ attr-2.4.43/libattr/attr_copy_action.c	2009-02-17 09:50:38.000000000 +0100
@@ -53,7 +53,7 @@ free_attr_actions(void)
 static int
 attr_parse_attr_conf(struct error_context *ctx)
 {
-	char *text, *t;
+	char *text = NULL, *t;
 	size_t size_guess = 4096, len;
 	FILE *file;
 	char *pattern = NULL;
@@ -64,15 +64,16 @@ attr_parse_attr_conf(struct error_contex
 		return 0;
 
 repeat:
-	text = malloc(size_guess + 1);
-	if (!text)
-		goto fail;
-
 	if ((file = fopen(ATTR_CONF, "r")) == NULL) {
 		if (errno == ENOENT)
 			return 0;
 		goto fail;
 	}
+
+	text = malloc(size_guess + 1);
+	if (!text)
+		goto fail;
+
 	len = fread(text, 1, size_guess, file);
 	if (ferror(file))
 		goto fail;
@@ -140,10 +141,12 @@ fail:
 		quote_free (ctx, q);
 	}
 
-	free(pattern);
+	if (pattern)
+		free(pattern);
 	if (file)
 		fclose(file);
-	free(text);
+	if (text)
+		free(text);
 	free_attr_actions();
 	return -1;
 }

[-- Attachment #3: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2009-02-17 11:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-17 11:50 Zdenek Prikryl [this message]
2009-02-17 12:04 ` libattr - severe memory leaks from attr_copy_file() Arkadiusz Miskiewicz
2009-02-18  7:08   ` Timothy Shimmin
  -- strict thread matches above, loose matches on Subject: below --
2009-02-19  7:04 Zdenek Prikryl
2009-02-19 16:31 ` Eric Sandeen
2009-02-20  0:33 ` Timothy Shimmin

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=499AA47A.2050106@redhat.com \
    --to=zprikryl@redhat.com \
    --cc=xfs@oss.sgi.com \
    /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