4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek Common utilities for check-based tests using talloc.
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek Martin Nagy <mnagy@redhat.com>
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek Copyright (C) Red Hat, Inc 2009
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek This program is free software; you can redistribute it and/or modify
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek it under the terms of the GNU General Public License as published by
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek (at your option) any later version.
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek This program is distributed in the hope that it will be useful,
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek GNU General Public License for more details.
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek You should have received a copy of the GNU General Public License
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
f4bcfcb1b91bfa6a568c4c99c2b3d16cd86090c6Lukas Slebodnikcheck_leaks(TALLOC_CTX *ctx, size_t bytes, const char *location)
24000ed5b08499b49595436b8a3b348fcd4012deLukas Slebodnik return false;
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek fprintf(stderr, "Leak report for %s:\n", location);
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek _set_leak_err_msg("%s: memory leaks detected, %zd bytes still allocated",
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return false;
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return true;
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek snapshot->bytes_allocated = talloc_total_size(ctx);
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek_check_leaks_pop(TALLOC_CTX *ctx, const char *location)
24000ed5b08499b49595436b8a3b348fcd4012deLukas Slebodnik return false;
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek _set_leak_err_msg("%s: trying to pop an empty stack", location);
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return false;
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return false;
f4bcfcb1b91bfa6a568c4c99c2b3d16cd86090c6Lukas Slebodnik return check_leaks(old_ctx, bytes_allocated, location);
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return false;
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return true;
20a2be57d764f58c4a6532310331e26a3273ada8Lukas Slebodnik res = check_leaks_pop(global_talloc_context);
20a2be57d764f58c4a6532310331e26a3273ada8Lukas Slebodnik _set_leak_err_msg("check_leaks_pop failed in leak_check_teardown");
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek _set_leak_err_msg("Exiting with a non-empty stack");
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozek return false;