mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
util/nvmutil: Further reduce memory usage
Allocate memory based on nf instead of partsize. nf is the number of bytes actually read from each part of the file. Now if the user is running setmac for example, 256 bytes of memory will be allocated regardless of gbe file size, whereas it would have previously allocated 8KB, 16KB or 128KB depending on the file. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -198,10 +198,6 @@ openFiles(const char *path)
|
||||
void
|
||||
readGbe(void)
|
||||
{
|
||||
char *buf = malloc(partsize << 1);
|
||||
if (buf == NULL)
|
||||
err(errno, "Can't malloc %ld B for '%s'", partsize, filename);
|
||||
|
||||
if ((cmd == writeGbe) || (cmd == cmd_copy))
|
||||
nf = partsize; /* read/write the entire block */
|
||||
else
|
||||
@@ -210,9 +206,13 @@ readGbe(void)
|
||||
if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick))
|
||||
skipread[part ^ 1] = 1; /* only read the user-specified part */
|
||||
|
||||
char *buf = malloc(nf << 1);
|
||||
if (buf == NULL)
|
||||
err(errno, "Can't malloc %ld B for '%s'", partsize, filename);
|
||||
|
||||
/* we pread per-part, so each part has its own pointer: */
|
||||
gbe[0] = (size_t) buf;
|
||||
gbe[1] = gbe[0] + partsize;
|
||||
gbe[1] = gbe[0] + nf;
|
||||
|
||||
for (int p = 0; p < 2; p++) {
|
||||
if (skipread[p])
|
||||
|
||||
Reference in New Issue
Block a user