Commit 37ed19d5 authored by Alexey Fomenko's avatar Alexey Fomenko Committed by Linus Torvalds

scripts/mod/modpost.c: fix memory leak

sec2annotation returns malloc'ed buffer directly to printf as an argument.
 Free this buffer after printing.
Signed-off-by: default avatarAlexey Fomenko <ext-alexey.fomenko@nokia.com>
Cc: Trevor Keith <tsrk@tsrk.net>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Michal Marek <mmarek@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e269b085
...@@ -1245,6 +1245,8 @@ static void report_sec_mismatch(const char *modname, ...@@ -1245,6 +1245,8 @@ static void report_sec_mismatch(const char *modname,
{ {
const char *from, *from_p; const char *from, *from_p;
const char *to, *to_p; const char *to, *to_p;
char *prl_from;
char *prl_to;
switch (from_is_func) { switch (from_is_func) {
case 0: from = "variable"; from_p = ""; break; case 0: from = "variable"; from_p = ""; break;
...@@ -1268,16 +1270,21 @@ static void report_sec_mismatch(const char *modname, ...@@ -1268,16 +1270,21 @@ static void report_sec_mismatch(const char *modname,
switch (mismatch->mismatch) { switch (mismatch->mismatch) {
case TEXT_TO_ANY_INIT: case TEXT_TO_ANY_INIT:
prl_from = sec2annotation(fromsec);
prl_to = sec2annotation(tosec);
fprintf(stderr, fprintf(stderr,
"The function %s%s() references\n" "The function %s%s() references\n"
"the %s %s%s%s.\n" "the %s %s%s%s.\n"
"This is often because %s lacks a %s\n" "This is often because %s lacks a %s\n"
"annotation or the annotation of %s is wrong.\n", "annotation or the annotation of %s is wrong.\n",
sec2annotation(fromsec), fromsym, prl_from, fromsym,
to, sec2annotation(tosec), tosym, to_p, to, prl_to, tosym, to_p,
fromsym, sec2annotation(tosec), tosym); fromsym, prl_to, tosym);
free(prl_from);
free(prl_to);
break; break;
case DATA_TO_ANY_INIT: { case DATA_TO_ANY_INIT: {
prl_to = sec2annotation(tosec);
const char *const *s = mismatch->symbol_white_list; const char *const *s = mismatch->symbol_white_list;
fprintf(stderr, fprintf(stderr,
"The variable %s references\n" "The variable %s references\n"
...@@ -1285,20 +1292,24 @@ static void report_sec_mismatch(const char *modname, ...@@ -1285,20 +1292,24 @@ static void report_sec_mismatch(const char *modname,
"If the reference is valid then annotate the\n" "If the reference is valid then annotate the\n"
"variable with __init* or __refdata (see linux/init.h) " "variable with __init* or __refdata (see linux/init.h) "
"or name the variable:\n", "or name the variable:\n",
fromsym, to, sec2annotation(tosec), tosym, to_p); fromsym, to, prl_to, tosym, to_p);
while (*s) while (*s)
fprintf(stderr, "%s, ", *s++); fprintf(stderr, "%s, ", *s++);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
free(prl_to);
break; break;
} }
case TEXT_TO_ANY_EXIT: case TEXT_TO_ANY_EXIT:
prl_to = sec2annotation(tosec);
fprintf(stderr, fprintf(stderr,
"The function %s() references a %s in an exit section.\n" "The function %s() references a %s in an exit section.\n"
"Often the %s %s%s has valid usage outside the 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", "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; break;
case DATA_TO_ANY_EXIT: { case DATA_TO_ANY_EXIT: {
prl_to = sec2annotation(tosec);
const char *const *s = mismatch->symbol_white_list; const char *const *s = mismatch->symbol_white_list;
fprintf(stderr, fprintf(stderr,
"The variable %s references\n" "The variable %s references\n"
...@@ -1306,24 +1317,31 @@ static void report_sec_mismatch(const char *modname, ...@@ -1306,24 +1317,31 @@ static void report_sec_mismatch(const char *modname,
"If the reference is valid then annotate the\n" "If the reference is valid then annotate the\n"
"variable with __exit* (see linux/init.h) or " "variable with __exit* (see linux/init.h) or "
"name the variable:\n", "name the variable:\n",
fromsym, to, sec2annotation(tosec), tosym, to_p); fromsym, to, prl_to, tosym, to_p);
while (*s) while (*s)
fprintf(stderr, "%s, ", *s++); fprintf(stderr, "%s, ", *s++);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
free(prl_to);
break; break;
} }
case XXXINIT_TO_SOME_INIT: case XXXINIT_TO_SOME_INIT:
case XXXEXIT_TO_SOME_EXIT: case XXXEXIT_TO_SOME_EXIT:
prl_from = sec2annotation(fromsec);
prl_to = sec2annotation(tosec);
fprintf(stderr, fprintf(stderr,
"The %s %s%s%s references\n" "The %s %s%s%s references\n"
"a %s %s%s%s.\n" "a %s %s%s%s.\n"
"If %s is only used by %s then\n" "If %s is only used by %s then\n"
"annotate %s with a matching annotation.\n", "annotate %s with a matching annotation.\n",
from, sec2annotation(fromsec), fromsym, from_p, from, prl_from, fromsym, from_p,
to, sec2annotation(tosec), tosym, to_p, to, prl_to, tosym, to_p,
tosym, fromsym, tosym); tosym, fromsym, tosym);
free(prl_from);
free(prl_to);
break; break;
case ANY_INIT_TO_ANY_EXIT: case ANY_INIT_TO_ANY_EXIT:
prl_from = sec2annotation(fromsec);
prl_to = sec2annotation(tosec);
fprintf(stderr, fprintf(stderr,
"The %s %s%s%s references\n" "The %s %s%s%s references\n"
"a %s %s%s%s.\n" "a %s %s%s%s.\n"
...@@ -1332,11 +1350,15 @@ static void report_sec_mismatch(const char *modname, ...@@ -1332,11 +1350,15 @@ static void report_sec_mismatch(const char *modname,
"uses functionality in the exit path.\n" "uses functionality in the exit path.\n"
"The fix is often to remove the %sannotation of\n" "The fix is often to remove the %sannotation of\n"
"%s%s so it may be used outside an exit section.\n", "%s%s so it may be used outside an exit section.\n",
from, sec2annotation(fromsec), fromsym, from_p, from, prl_from, fromsym, from_p,
to, sec2annotation(tosec), tosym, to_p, to, prl_to, tosym, to_p,
sec2annotation(tosec), tosym, to_p); sec2annotation(tosec), tosym, to_p);
free(prl_from);
free(prl_to);
break; break;
case ANY_EXIT_TO_ANY_INIT: case ANY_EXIT_TO_ANY_INIT:
prl_from = sec2annotation(fromsec);
prl_to = sec2annotation(tosec);
fprintf(stderr, fprintf(stderr,
"The %s %s%s%s references\n" "The %s %s%s%s references\n"
"a %s %s%s%s.\n" "a %s %s%s%s.\n"
...@@ -1345,16 +1367,20 @@ static void report_sec_mismatch(const char *modname, ...@@ -1345,16 +1367,20 @@ static void report_sec_mismatch(const char *modname,
"uses functionality in the init path.\n" "uses functionality in the init path.\n"
"The fix is often to remove the %sannotation of\n" "The fix is often to remove the %sannotation of\n"
"%s%s so it may be used outside an init section.\n", "%s%s so it may be used outside an init section.\n",
from, sec2annotation(fromsec), fromsym, from_p, from, prl_from, fromsym, from_p,
to, sec2annotation(tosec), tosym, to_p, to, prl_to, tosym, to_p,
sec2annotation(tosec), tosym, to_p); prl_to, tosym, to_p);
free(prl_from);
free(prl_to);
break; break;
case EXPORT_TO_INIT_EXIT: case EXPORT_TO_INIT_EXIT:
prl_to = sec2annotation(tosec);
fprintf(stderr, fprintf(stderr,
"The symbol %s is exported and annotated %s\n" "The symbol %s is exported and annotated %s\n"
"Fix this by removing the %sannotation of %s " "Fix this by removing the %sannotation of %s "
"or drop the export.\n", "or drop the export.\n",
tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); tosym, prl_to, prl_to, tosym);
free(prl_to);
break; break;
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment