Browse Source

tests: fix leaks spotted by ASAN

Always allocate from open_blob_rw(), to simplify memory management.

The fixes are not exhaustive.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
Marc-André Lureau 2 years ago committed by David Gibson
parent
commit
083ab26da8
  1. 1
      tests/appendprop2.c
  2. 2
      tests/appendprop_addrrange.c
  3. 1
      tests/check_path.c
  4. 7
      tests/del_node.c
  5. 8
      tests/del_property.c
  6. 1
      tests/overlay.c
  7. 8
      tests/set_name.c
  8. 1
      tests/setprop.c
  9. 2
      tests/tests.h
  10. 15
      tests/testutils.c

1
tests/appendprop2.c

@ -36,6 +36,7 @@ int main(int argc, char *argv[])


buf = xmalloc(SPACE); buf = xmalloc(SPACE);
CHECK(fdt_open_into(fdt, buf, SPACE)); CHECK(fdt_open_into(fdt, buf, SPACE));
free(fdt);
fdt = buf; fdt = buf;


CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes))); CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));

2
tests/appendprop_addrrange.c

@ -36,7 +36,7 @@ int main(int argc, char *argv[])
err = fdt_open_into(fdt, buf, 0x1000); err = fdt_open_into(fdt, buf, 0x1000);
if (err) if (err)
FAIL("fdt_open_into(): %s", fdt_strerror(err)); FAIL("fdt_open_into(): %s", fdt_strerror(err));

free(fdt);
fdt = buf; fdt = buf;


/* Set up */ /* Set up */

1
tests/check_path.c

@ -32,6 +32,7 @@ static void *open_dt(char *path)
* Resize our DTs to 4k so that we have room to operate on * Resize our DTs to 4k so that we have room to operate on
*/ */
CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE)); CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE));
free(dt);


return copy; return copy;
} }

7
tests/del_node.c

@ -18,15 +18,16 @@


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
void *fdt; void *fdt, *blob;
int subnode1_offset, subnode2_offset, subsubnode2_offset; int subnode1_offset, subnode2_offset, subsubnode2_offset;
int err; int err;
int oldsize, delsize, newsize; int oldsize, delsize, newsize;


test_init(argc, argv); test_init(argc, argv);
fdt = load_blob_arg(argc, argv); blob = load_blob_arg(argc, argv);


fdt = open_blob_rw(fdt); fdt = open_blob_rw(blob);
free(blob);


oldsize = fdt_totalsize(fdt); oldsize = fdt_totalsize(fdt);



8
tests/del_property.c

@ -18,16 +18,17 @@


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
void *fdt; void *fdt, *blob;
const uint32_t *intp; const uint32_t *intp;
const char *strp; const char *strp;
int err, lenerr; int err, lenerr;
int oldsize, delsize, newsize; int oldsize, delsize, newsize;


test_init(argc, argv); test_init(argc, argv);
fdt = load_blob_arg(argc, argv); blob = load_blob_arg(argc, argv);


fdt = open_blob_rw(fdt); fdt = open_blob_rw(blob);
free(blob);


oldsize = fdt_totalsize(fdt); oldsize = fdt_totalsize(fdt);


@ -73,5 +74,6 @@ int main(int argc, char *argv[])
if (newsize >= oldsize) if (newsize >= oldsize)
FAIL("Tree failed to shrink after deletions"); FAIL("Tree failed to shrink after deletions");


free(fdt);
PASS(); PASS();
} }

1
tests/overlay.c

@ -186,6 +186,7 @@ static void *open_dt(char *path)
* Resize our DTs to 4k so that we have room to operate on * Resize our DTs to 4k so that we have room to operate on
*/ */
CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE)); CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE));
free(dt);


return copy; return copy;
} }

8
tests/set_name.c

@ -69,15 +69,17 @@ static void check_set_name(void *fdt, const char *path, const char *newname)


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
void *fdt; void *fdt, *blob;


test_init(argc, argv); test_init(argc, argv);
fdt = load_blob_arg(argc, argv); blob = load_blob_arg(argc, argv);
fdt = open_blob_rw(fdt); fdt = open_blob_rw(blob);
free(blob);


check_set_name(fdt, "/subnode@1", "subnode@17"); check_set_name(fdt, "/subnode@1", "subnode@17");
check_set_name(fdt, "/subnode@2/subsubnode@0", "fred@0"); check_set_name(fdt, "/subnode@2/subsubnode@0", "fred@0");
check_set_name(fdt, "/subnode@17/subsubnode", "something@0"); check_set_name(fdt, "/subnode@17/subsubnode", "something@0");


free(fdt);
PASS(); PASS();
} }

1
tests/setprop.c

@ -36,6 +36,7 @@ int main(int argc, char *argv[])
if (err) if (err)
FAIL("fdt_open_into(): %s", fdt_strerror(err)); FAIL("fdt_open_into(): %s", fdt_strerror(err));


free(fdt);
fdt = buf; fdt = buf;


intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);

2
tests/tests.h

@ -123,7 +123,7 @@ void vg_prepare_blob(void *fdt, size_t bufsize);
void *load_blob(const char *filename); void *load_blob(const char *filename);
void *load_blob_arg(int argc, char *argv[]); void *load_blob_arg(int argc, char *argv[]);
void save_blob(const char *filename, void *blob); void save_blob(const char *filename, void *blob);
void *open_blob_rw(void *blob); void *open_blob_rw(const void *blob);


#include "util.h" #include "util.h"



15
tests/testutils.c

@ -340,19 +340,14 @@ void save_blob(const char *filename, void *fdt)
free(tmp); free(tmp);
} }


void *open_blob_rw(void *blob) void *open_blob_rw(const void *blob)
{ {
int err; int err;
void *buf = blob; void *buf;
int newsize = fdt_totalsize(blob) + 8;


err = fdt_open_into(blob, buf, fdt_totalsize(blob)); buf = xmalloc(newsize);
if (err == -FDT_ERR_NOSPACE) { err = fdt_open_into(blob, buf, newsize);
/* Ran out of space converting to v17 */
int newsize = fdt_totalsize(blob) + 8;

buf = xmalloc(newsize);
err = fdt_open_into(blob, buf, newsize);
}
if (err) if (err)
FAIL("fdt_open_into(): %s", fdt_strerror(err)); FAIL("fdt_open_into(): %s", fdt_strerror(err));
return buf; return buf;

Loading…
Cancel
Save