mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-01-18 07:11:00 +01:00
Right now the free() call is not intercepted since all this is done using macros and that would break a lot of stuff. Instead a __free() macro was provided but never used. In addition it used to only report a zero size, which is not very convenient. With this patch comes a better solution. Instead it provides a new will_free() macro that can be prepended before a call to free(). It only keeps the counters up to date, and also supports being passed a size. The pool_free_area() command now uses it, which finally allows the stats to look correct: pool-os.h:38 MALLOC size: 5802127832 calls: 3868044 size/call: 1500 pool-os.h:47 FREE size: 5800041576 calls: 3867444 size/call: 1499 The few other places directly calling free() could now be instrumented to use this and to pass the correct sizeof() when known.
86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
/*
|
|
* include/haproxy/pool-os.h
|
|
* OS-level interface for memory management
|
|
*
|
|
* Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
* exclusively.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef _HAPROXY_POOL_OS_H
|
|
#define _HAPROXY_POOL_OS_H
|
|
|
|
#include <stdlib.h>
|
|
#include <haproxy/api.h>
|
|
|
|
|
|
#ifndef DEBUG_UAF
|
|
|
|
/************* normal allocator *************/
|
|
|
|
/* allocates an area of size <size> and returns it. The semantics are similar
|
|
* to those of malloc().
|
|
*/
|
|
static forceinline void *pool_alloc_area(size_t size)
|
|
{
|
|
return malloc(size);
|
|
}
|
|
|
|
/* frees an area <area> of size <size> allocated by pool_alloc_area(). The
|
|
* semantics are identical to free() except that the size is specified and
|
|
* may be ignored.
|
|
*/
|
|
static forceinline void pool_free_area(void *area, size_t __maybe_unused size)
|
|
{
|
|
will_free(area, size);
|
|
free(area);
|
|
}
|
|
|
|
#else
|
|
|
|
/************* use-after-free allocator *************/
|
|
|
|
void *pool_alloc_area_uaf(size_t size);
|
|
void pool_free_area_uaf(void *area, size_t size);
|
|
|
|
|
|
/* allocates an area of size <size> and returns it. The semantics are similar
|
|
* to those of malloc().
|
|
*/
|
|
static forceinline void *pool_alloc_area(size_t size)
|
|
{
|
|
return pool_alloc_area_uaf(size);
|
|
}
|
|
|
|
/* frees an area <area> of size <size> allocated by pool_alloc_area(). The
|
|
* semantics are identical to free() except that the size is specified and
|
|
* may be ignored.
|
|
*/
|
|
static forceinline void pool_free_area(void *area, size_t size)
|
|
{
|
|
pool_free_area_uaf(area, size);
|
|
}
|
|
|
|
#endif /* DEBUG_UAF */
|
|
|
|
#endif /* _HAPROXY_POOL_OS_H */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-indent-level: 8
|
|
* c-basic-offset: 8
|
|
* End:
|
|
*/
|