All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fixed resource leak in scripts/mod/modpost.c
@ 2010-08-04 12:38 Alexey Fomenko
  2010-08-04 22:42 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Fomenko @ 2010-08-04 12:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Trevor Keith, Andrew Morton

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

sec2annotation returns malloc'ed buffer directly to printf as an
argument. Patch lets free this buffer after printing. 

[-- Attachment #2: 0001-fixed-resource-leak-in-scripts-mod-modpost.c.patch --]
[-- Type: text/x-patch, Size: 5400 bytes --]

>From 57bde7f335730f95eac75bcec5a27fb6686df25a Mon Sep 17 00:00:00 2001
From: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
Date: Tue, 27 Jul 2010 17:59:04 +0300
Subject: [PATCH] fixed resource leak in scripts/mod/modpost.c


Signed-off-by: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
---
 scripts/mod/modpost.c |   59 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 801a16a..1466691 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1158,6 +1158,9 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
 {
 	const char *from, *from_p;
 	const char *to, *to_p;
+	char *prl_from;
+	char *prl_to;
+
 
 	switch (from_is_func) {
 	case 0: from = "variable"; from_p = "";   break;
@@ -1181,16 +1184,21 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
 
 	switch (mismatch) {
 	case TEXT_TO_INIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The function %s%s() references\n"
 		"the %s %s%s%s.\n"
 		"This is often because %s lacks a %s\n"
 		"annotation or the annotation of %s is wrong.\n",
-		sec2annotation(fromsec), fromsym,
-		to, sec2annotation(tosec), tosym, to_p,
-		fromsym, sec2annotation(tosec), tosym);
+		prl_from, fromsym,
+		to, prl_to, tosym, to_p,
+		fromsym, prl_to, tosym);
+		free(prl_from);
+		free(prl_to);
 		break;
 	case DATA_TO_INIT: {
+		prl_to = sec2annotation(tosec);
 		const char **s = symbol_white_list;
 		fprintf(stderr,
 		"The variable %s references\n"
@@ -1198,20 +1206,24 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
 		"If the reference is valid then annotate the\n"
 		"variable with __init* or __refdata (see linux/init.h) "
 		"or name the variable:\n",
-		fromsym, to, sec2annotation(tosec), tosym, to_p);
+		fromsym, to, prl_to, tosym, to_p);
 		while (*s)
 			fprintf(stderr, "%s, ", *s++);
 		fprintf(stderr, "\n");
+		free(prl_to);
 		break;
 	}
 	case TEXT_TO_EXIT:
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The function %s() references a %s in an exit section.\n"
 		"Often the %s %s%s has valid usage outside the exit section\n"
 		"and the fix is to remove the %sannotation of %s.\n",
-		fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym);
+		fromsym, to, to, tosym, to_p, prl_to, tosym);
+		free(prl_to);
 		break;
 	case DATA_TO_EXIT: {
+		prl_to = sec2annotation(tosec);
 		const char **s = symbol_white_list;
 		fprintf(stderr,
 		"The variable %s references\n"
@@ -1219,24 +1231,31 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
 		"If the reference is valid then annotate the\n"
 		"variable with __exit* (see linux/init.h) or "
 		"name the variable:\n",
-		fromsym, to, sec2annotation(tosec), tosym, to_p);
+		fromsym, to, prl_to, tosym, to_p);
 		while (*s)
 			fprintf(stderr, "%s, ", *s++);
 		fprintf(stderr, "\n");
+		free(prl_to);
 		break;
 	}
 	case XXXINIT_TO_INIT:
 	case XXXEXIT_TO_EXIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The %s %s%s%s references\n"
 		"a %s %s%s%s.\n"
 		"If %s is only used by %s then\n"
 		"annotate %s with a matching annotation.\n",
-		from, sec2annotation(fromsec), fromsym, from_p,
-		to, sec2annotation(tosec), tosym, to_p,
+		from, prl_from, fromsym, from_p,
+		to, prl_to, tosym, to_p,
 		tosym, fromsym, tosym);
+		free(prl_from);
+		free(prl_to);
 		break;
 	case INIT_TO_EXIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The %s %s%s%s references\n"
 		"a %s %s%s%s.\n"
@@ -1245,11 +1264,15 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
 		"uses functionality in the exit path.\n"
 		"The fix is often to remove the %sannotation of\n"
 		"%s%s so it may be used outside an exit section.\n",
-		from, sec2annotation(fromsec), fromsym, from_p,
-		to, sec2annotation(tosec), tosym, to_p,
-		sec2annotation(tosec), tosym, to_p);
+		from, prl_from, fromsym, from_p,
+		to, prl_to, tosym, to_p,
+		prl_to, tosym, to_p);
+		free(prl_from);
+		free(prl_to);
 		break;
 	case EXIT_TO_INIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The %s %s%s%s references\n"
 		"a %s %s%s%s.\n"
@@ -1258,16 +1281,22 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
 		"uses functionality in the init path.\n"
 		"The fix is often to remove the %sannotation of\n"
 		"%s%s so it may be used outside an init section.\n",
-		from, sec2annotation(fromsec), fromsym, from_p,
-		to, sec2annotation(tosec), tosym, to_p,
-		sec2annotation(tosec), tosym, to_p);
+		from, prl_from, fromsym, from_p,
+		to, prl_to, tosym, to_p,
+		to, tosym, to_p);
+		free(prl_from);
+		free(prl_to);
 		break;
 	case EXPORT_TO_INIT_EXIT:
+		prl_from = sec2annotation(fromsec);
+		prl_to = sec2annotation(tosec);
 		fprintf(stderr,
 		"The symbol %s is exported and annotated %s\n"
 		"Fix this by removing the %sannotation of %s "
 		"or drop the export.\n",
-		tosym, sec2annotation(tosec), sec2annotation(tosec), tosym);
+		tosym, prl_to, prl_to, tosym);
+		free(prl_from);
+		free(prl_to);
 	case NO_MISMATCH:
 		/* To get warnings on missing members */
 		break;
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fixed resource leak in scripts/mod/modpost.c
  2010-08-04 12:38 [PATCH] fixed resource leak in scripts/mod/modpost.c Alexey Fomenko
@ 2010-08-04 22:42 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2010-08-04 22:42 UTC (permalink / raw)
  To: Alexey Fomenko; +Cc: linux-kernel, Trevor Keith, Rusty Russell

On Wed, 04 Aug 2010 15:38:43 +0300
Alexey Fomenko <ext-alexey.fomenko@nokia.com> wrote:

> sec2annotation returns malloc'ed buffer directly to printf as an
> argument. Patch lets free this buffer after printing. 
> 
> 
> [0001-fixed-resource-leak-in-scripts-mod-modpost.c.patch  text/x-patch (5.3KB)]
> >From 57bde7f335730f95eac75bcec5a27fb6686df25a Mon Sep 17 00:00:00 2001
> From: Alexey Fomenko <ext-alexey.fomenko@nokia.com>
> Date: Tue, 27 Jul 2010 17:59:04 +0300
> Subject: [PATCH] fixed resource leak in scripts/mod/modpost.c
> 

Against 2.6.35:

patching file scripts/mod/modpost.c
Hunk #1 succeeded at 1195 (offset 37 lines).
Hunk #2 FAILED at 1221.
Hunk #3 FAILED at 1243.
Hunk #4 FAILED at 1268.
Hunk #5 FAILED at 1301.
Hunk #6 FAILED at 1318.
5 out of 6 hunks FAILED -- saving rejects to file scripts/mod/modpost.c.rej

please check up on that.

Please also cc Rusty on this change.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-04 22:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-04 12:38 [PATCH] fixed resource leak in scripts/mod/modpost.c Alexey Fomenko
2010-08-04 22:42 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.