diff options
author | Alexey Fomenko <ext-alexey.fomenko@nokia.com> | 2010-08-09 20:20:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-09 23:45:05 -0400 |
commit | 37ed19d5cce35a40d3913cf9aa208ce9f60db3d7 (patch) | |
tree | a4e3363f5a4c059330372b2f686112bfee6364b2 | |
parent | e269b085175acf03fc687a7416b9fd84aa9c6c23 (diff) |
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: Alexey 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | scripts/mod/modpost.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index c827309c29c..1ce655dde99 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -1245,6 +1245,8 @@ static void report_sec_mismatch(const char *modname, | |||
1245 | { | 1245 | { |
1246 | const char *from, *from_p; | 1246 | const char *from, *from_p; |
1247 | const char *to, *to_p; | 1247 | const char *to, *to_p; |
1248 | char *prl_from; | ||
1249 | char *prl_to; | ||
1248 | 1250 | ||
1249 | switch (from_is_func) { | 1251 | switch (from_is_func) { |
1250 | case 0: from = "variable"; from_p = ""; break; | 1252 | case 0: from = "variable"; from_p = ""; break; |
@@ -1268,16 +1270,21 @@ static void report_sec_mismatch(const char *modname, | |||
1268 | 1270 | ||
1269 | switch (mismatch->mismatch) { | 1271 | switch (mismatch->mismatch) { |
1270 | case TEXT_TO_ANY_INIT: | 1272 | case TEXT_TO_ANY_INIT: |
1273 | prl_from = sec2annotation(fromsec); | ||
1274 | prl_to = sec2annotation(tosec); | ||
1271 | fprintf(stderr, | 1275 | fprintf(stderr, |
1272 | "The function %s%s() references\n" | 1276 | "The function %s%s() references\n" |
1273 | "the %s %s%s%s.\n" | 1277 | "the %s %s%s%s.\n" |
1274 | "This is often because %s lacks a %s\n" | 1278 | "This is often because %s lacks a %s\n" |
1275 | "annotation or the annotation of %s is wrong.\n", | 1279 | "annotation or the annotation of %s is wrong.\n", |
1276 | sec2annotation(fromsec), fromsym, | 1280 | prl_from, fromsym, |
1277 | to, sec2annotation(tosec), tosym, to_p, | 1281 | to, prl_to, tosym, to_p, |
1278 | fromsym, sec2annotation(tosec), tosym); | 1282 | fromsym, prl_to, tosym); |
1283 | free(prl_from); | ||
1284 | free(prl_to); | ||
1279 | break; | 1285 | break; |
1280 | case DATA_TO_ANY_INIT: { | 1286 | case DATA_TO_ANY_INIT: { |
1287 | prl_to = sec2annotation(tosec); | ||
1281 | const char *const *s = mismatch->symbol_white_list; | 1288 | const char *const *s = mismatch->symbol_white_list; |
1282 | fprintf(stderr, | 1289 | fprintf(stderr, |
1283 | "The variable %s references\n" | 1290 | "The variable %s references\n" |
@@ -1285,20 +1292,24 @@ static void report_sec_mismatch(const char *modname, | |||
1285 | "If the reference is valid then annotate the\n" | 1292 | "If the reference is valid then annotate the\n" |
1286 | "variable with __init* or __refdata (see linux/init.h) " | 1293 | "variable with __init* or __refdata (see linux/init.h) " |
1287 | "or name the variable:\n", | 1294 | "or name the variable:\n", |
1288 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1295 | fromsym, to, prl_to, tosym, to_p); |
1289 | while (*s) | 1296 | while (*s) |
1290 | fprintf(stderr, "%s, ", *s++); | 1297 | fprintf(stderr, "%s, ", *s++); |
1291 | fprintf(stderr, "\n"); | 1298 | fprintf(stderr, "\n"); |
1299 | free(prl_to); | ||
1292 | break; | 1300 | break; |
1293 | } | 1301 | } |
1294 | case TEXT_TO_ANY_EXIT: | 1302 | case TEXT_TO_ANY_EXIT: |
1303 | prl_to = sec2annotation(tosec); | ||
1295 | fprintf(stderr, | 1304 | fprintf(stderr, |
1296 | "The function %s() references a %s in an exit section.\n" | 1305 | "The function %s() references a %s in an exit section.\n" |
1297 | "Often the %s %s%s has valid usage outside the exit section\n" | 1306 | "Often the %s %s%s has valid usage outside the exit section\n" |
1298 | "and the fix is to remove the %sannotation of %s.\n", | 1307 | "and the fix is to remove the %sannotation of %s.\n", |
1299 | fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); | 1308 | fromsym, to, to, tosym, to_p, prl_to, tosym); |
1309 | free(prl_to); | ||
1300 | break; | 1310 | break; |
1301 | case DATA_TO_ANY_EXIT: { | 1311 | case DATA_TO_ANY_EXIT: { |
1312 | prl_to = sec2annotation(tosec); | ||
1302 | const char *const *s = mismatch->symbol_white_list; | 1313 | const char *const *s = mismatch->symbol_white_list; |
1303 | fprintf(stderr, | 1314 | fprintf(stderr, |
1304 | "The variable %s references\n" | 1315 | "The variable %s references\n" |
@@ -1306,24 +1317,31 @@ static void report_sec_mismatch(const char *modname, | |||
1306 | "If the reference is valid then annotate the\n" | 1317 | "If the reference is valid then annotate the\n" |
1307 | "variable with __exit* (see linux/init.h) or " | 1318 | "variable with __exit* (see linux/init.h) or " |
1308 | "name the variable:\n", | 1319 | "name the variable:\n", |
1309 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1320 | fromsym, to, prl_to, tosym, to_p); |
1310 | while (*s) | 1321 | while (*s) |
1311 | fprintf(stderr, "%s, ", *s++); | 1322 | fprintf(stderr, "%s, ", *s++); |
1312 | fprintf(stderr, "\n"); | 1323 | fprintf(stderr, "\n"); |
1324 | free(prl_to); | ||
1313 | break; | 1325 | break; |
1314 | } | 1326 | } |
1315 | case XXXINIT_TO_SOME_INIT: | 1327 | case XXXINIT_TO_SOME_INIT: |
1316 | case XXXEXIT_TO_SOME_EXIT: | 1328 | case XXXEXIT_TO_SOME_EXIT: |
1329 | prl_from = sec2annotation(fromsec); | ||
1330 | prl_to = sec2annotation(tosec); | ||
1317 | fprintf(stderr, | 1331 | fprintf(stderr, |
1318 | "The %s %s%s%s references\n" | 1332 | "The %s %s%s%s references\n" |
1319 | "a %s %s%s%s.\n" | 1333 | "a %s %s%s%s.\n" |
1320 | "If %s is only used by %s then\n" | 1334 | "If %s is only used by %s then\n" |
1321 | "annotate %s with a matching annotation.\n", | 1335 | "annotate %s with a matching annotation.\n", |
1322 | from, sec2annotation(fromsec), fromsym, from_p, | 1336 | from, prl_from, fromsym, from_p, |
1323 | to, sec2annotation(tosec), tosym, to_p, | 1337 | to, prl_to, tosym, to_p, |
1324 | tosym, fromsym, tosym); | 1338 | tosym, fromsym, tosym); |
1339 | free(prl_from); | ||
1340 | free(prl_to); | ||
1325 | break; | 1341 | break; |
1326 | case ANY_INIT_TO_ANY_EXIT: | 1342 | case ANY_INIT_TO_ANY_EXIT: |
1343 | prl_from = sec2annotation(fromsec); | ||
1344 | prl_to = sec2annotation(tosec); | ||
1327 | fprintf(stderr, | 1345 | fprintf(stderr, |
1328 | "The %s %s%s%s references\n" | 1346 | "The %s %s%s%s references\n" |
1329 | "a %s %s%s%s.\n" | 1347 | "a %s %s%s%s.\n" |
@@ -1332,11 +1350,15 @@ static void report_sec_mismatch(const char *modname, | |||
1332 | "uses functionality in the exit path.\n" | 1350 | "uses functionality in the exit path.\n" |
1333 | "The fix is often to remove the %sannotation of\n" | 1351 | "The fix is often to remove the %sannotation of\n" |
1334 | "%s%s so it may be used outside an exit section.\n", | 1352 | "%s%s so it may be used outside an exit section.\n", |
1335 | from, sec2annotation(fromsec), fromsym, from_p, | 1353 | from, prl_from, fromsym, from_p, |
1336 | to, sec2annotation(tosec), tosym, to_p, | 1354 | to, prl_to, tosym, to_p, |
1337 | sec2annotation(tosec), tosym, to_p); | 1355 | sec2annotation(tosec), tosym, to_p); |
1356 | free(prl_from); | ||
1357 | free(prl_to); | ||
1338 | break; | 1358 | break; |
1339 | case ANY_EXIT_TO_ANY_INIT: | 1359 | case ANY_EXIT_TO_ANY_INIT: |
1360 | prl_from = sec2annotation(fromsec); | ||
1361 | prl_to = sec2annotation(tosec); | ||
1340 | fprintf(stderr, | 1362 | fprintf(stderr, |
1341 | "The %s %s%s%s references\n" | 1363 | "The %s %s%s%s references\n" |
1342 | "a %s %s%s%s.\n" | 1364 | "a %s %s%s%s.\n" |
@@ -1345,16 +1367,20 @@ static void report_sec_mismatch(const char *modname, | |||
1345 | "uses functionality in the init path.\n" | 1367 | "uses functionality in the init path.\n" |
1346 | "The fix is often to remove the %sannotation of\n" | 1368 | "The fix is often to remove the %sannotation of\n" |
1347 | "%s%s so it may be used outside an init section.\n", | 1369 | "%s%s so it may be used outside an init section.\n", |
1348 | from, sec2annotation(fromsec), fromsym, from_p, | 1370 | from, prl_from, fromsym, from_p, |
1349 | to, sec2annotation(tosec), tosym, to_p, | 1371 | to, prl_to, tosym, to_p, |
1350 | sec2annotation(tosec), tosym, to_p); | 1372 | prl_to, tosym, to_p); |
1373 | free(prl_from); | ||
1374 | free(prl_to); | ||
1351 | break; | 1375 | break; |
1352 | case EXPORT_TO_INIT_EXIT: | 1376 | case EXPORT_TO_INIT_EXIT: |
1377 | prl_to = sec2annotation(tosec); | ||
1353 | fprintf(stderr, | 1378 | fprintf(stderr, |
1354 | "The symbol %s is exported and annotated %s\n" | 1379 | "The symbol %s is exported and annotated %s\n" |
1355 | "Fix this by removing the %sannotation of %s " | 1380 | "Fix this by removing the %sannotation of %s " |
1356 | "or drop the export.\n", | 1381 | "or drop the export.\n", |
1357 | tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); | 1382 | tosym, prl_to, prl_to, tosym); |
1383 | free(prl_to); | ||
1358 | break; | 1384 | break; |
1359 | } | 1385 | } |
1360 | fprintf(stderr, "\n"); | 1386 | fprintf(stderr, "\n"); |