1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-01 06:01:16 +02:00

Fix memleaks due to incorrect usage of flashbuses_to_text

Corresponding to flashrom svn r1357.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
Stefan Tauner
2011-06-26 20:45:35 +00:00
parent b23df71149
commit 00155498a8
4 changed files with 18 additions and 8 deletions

View File

@ -1206,6 +1206,7 @@ int chipset_flash_enable(void)
struct pci_dev *dev = NULL; struct pci_dev *dev = NULL;
int ret = -2; /* Nothing! */ int ret = -2; /* Nothing! */
int i; int i;
char *s;
/* Now let's try to find the chipset we have... */ /* Now let's try to find the chipset we have... */
for (i = 0; chipset_enables[i].vendor_name != NULL; i++) { for (i = 0; chipset_enables[i].vendor_name != NULL; i++) {
@ -1244,8 +1245,9 @@ int chipset_flash_enable(void)
msg_pinfo("PROBLEMS, continuing anyway\n"); msg_pinfo("PROBLEMS, continuing anyway\n");
} }
msg_pinfo("This chipset supports the following protocols: %s.\n", s = flashbuses_to_text(buses_supported);
flashbuses_to_text(buses_supported)); msg_pinfo("This chipset supports the following protocols: %s.\n", s);
free(s);
return ret; return ret;
} }

View File

@ -1186,10 +1186,11 @@ notfound:
#endif #endif
snprintf(location, sizeof(location), "on %s", programmer_table[programmer].name); snprintf(location, sizeof(location), "on %s", programmer_table[programmer].name);
tmp = flashbuses_to_text(flash->bustype);
msg_cinfo("%s chip \"%s %s\" (%d kB, %s) %s.\n", msg_cinfo("%s chip \"%s %s\" (%d kB, %s) %s.\n",
force ? "Assuming" : "Found", force ? "Assuming" : "Found", fill_flash->vendor,
fill_flash->vendor, fill_flash->name, fill_flash->total_size, fill_flash->name, fill_flash->total_size, tmp, location);
flashbuses_to_text(fill_flash->bustype), location); free(tmp);
/* Flash registers will not be mapped if the chip was forced. Lock info /* Flash registers will not be mapped if the chip was forced. Lock info
* may be stored in registers, so avoid lock info printing. * may be stored in registers, so avoid lock info printing.

View File

@ -28,7 +28,7 @@
/* /*
* Return a string corresponding to the bustype parameter. * Return a string corresponding to the bustype parameter.
* Memory is obtained with malloc() and can be freed with free(). * Memory is obtained with malloc() and must be freed with free() by the caller.
*/ */
char *flashbuses_to_text(enum chipbustype bustype) char *flashbuses_to_text(enum chipbustype bustype)
{ {
@ -80,6 +80,7 @@ static void print_supported_chips(void)
int maxvendorlen = strlen("Vendor") + 1; int maxvendorlen = strlen("Vendor") + 1;
int maxchiplen = strlen("Device") + 1; int maxchiplen = strlen("Device") + 1;
const struct flashchip *f; const struct flashchip *f;
char *s;
for (f = flashchips; f->name != NULL; f++) { for (f = flashchips; f->name != NULL; f++) {
/* Ignore "unknown XXXX SPI chip" entries. */ /* Ignore "unknown XXXX SPI chip" entries. */
@ -152,7 +153,10 @@ static void print_supported_chips(void)
msg_ginfo("%d", f->total_size); msg_ginfo("%d", f->total_size);
for (i = 0; i < 10 - digits(f->total_size); i++) for (i = 0; i < 10 - digits(f->total_size); i++)
msg_ginfo(" "); msg_ginfo(" ");
msg_ginfo("%s\n", flashbuses_to_text(f->bustype));
s = flashbuses_to_text(f->bustype);
msg_ginfo("%s\n", s);
free(s);
} }
} }

View File

@ -203,6 +203,7 @@ static void print_supported_chips_wiki(int cols)
int i = 0, c = 1, chipcount = 0; int i = 0, c = 1, chipcount = 0;
const struct flashchip *f, *old = NULL; const struct flashchip *f, *old = NULL;
uint32_t t; uint32_t t;
char *s;
for (f = flashchips; f->name != NULL; f++) for (f = flashchips; f->name != NULL; f++)
chipcount++; chipcount++;
@ -221,10 +222,11 @@ static void print_supported_chips_wiki(int cols)
c = !c; c = !c;
t = f->tested; t = f->tested;
s = flashbuses_to_text(f->bustype);
printf("|- bgcolor=\"#%s\"\n| %s || %s || %d " printf("|- bgcolor=\"#%s\"\n| %s || %s || %d "
"|| %s || {{%s}} || {{%s}} || {{%s}} || {{%s}}\n", "|| %s || {{%s}} || {{%s}} || {{%s}} || {{%s}}\n",
(c == 1) ? "eeeeee" : "dddddd", f->vendor, f->name, (c == 1) ? "eeeeee" : "dddddd", f->vendor, f->name,
f->total_size, flashbuses_to_text(f->bustype), f->total_size, s,
(t & TEST_OK_PROBE) ? "OK" : (t & TEST_OK_PROBE) ? "OK" :
(t & TEST_BAD_PROBE) ? "No" : "?3", (t & TEST_BAD_PROBE) ? "No" : "?3",
(t & TEST_OK_READ) ? "OK" : (t & TEST_OK_READ) ? "OK" :
@ -233,6 +235,7 @@ static void print_supported_chips_wiki(int cols)
(t & TEST_BAD_ERASE) ? "No" : "?3", (t & TEST_BAD_ERASE) ? "No" : "?3",
(t & TEST_OK_WRITE) ? "OK" : (t & TEST_OK_WRITE) ? "OK" :
(t & TEST_BAD_WRITE) ? "No" : "?3"); (t & TEST_BAD_WRITE) ? "No" : "?3");
free(s);
/* Split table into 'cols' columns. */ /* Split table into 'cols' columns. */
if (i >= (chipcount / cols + 1)) { if (i >= (chipcount / cols + 1)) {