Skip to content

Commit

Permalink
mem: allow func_mem usage for system malloc too
Browse files Browse the repository at this point in the history
Reported by Dan Pascu on Devel user list
  • Loading branch information
razvancrainea committed Apr 18, 2019
1 parent 8e42ffa commit e82dbde
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
22 changes: 0 additions & 22 deletions mem/common.h
Expand Up @@ -93,28 +93,6 @@ typedef void *(*osips_block_realloc_f) (void *block, void *ptr, unsigned long si
typedef void (*osips_block_free_f) (void *block, void *ptr);
#endif

#ifdef DBG_MALLOC
typedef void *(*osips_malloc_f) (unsigned long size,
const char *file, const char *func, unsigned int line);
typedef void *(*osips_realloc_f) (void *ptr, unsigned long size,
const char *file, const char *func, unsigned int line);
typedef void (*osips_free_f) (void *ptr,
const char *file, const char *func, unsigned int line);
#define func_malloc(_func, _size) (_func)(_size, \
__FILE__, __FUNCTION__, __LINE__ )
#define func_realloc(_func, _ptr, _size) (_func)(_ptr, _size, \
__FILE__, __FUNCTION__, __LINE__ )
#define func_free(_func, _ptr) (_func)(_ptr, \
__FILE__, __FUNCTION__, __LINE__ )
#else
typedef void *(*osips_malloc_f) (unsigned long size);
typedef void *(*osips_realloc_f) (void *ptr, unsigned long size);
typedef void (*osips_free_f) (void *ptr);
#define func_malloc(_func, _size) (_func)(_size)
#define func_realloc(_func, _ptr, _size) (_func)(_ptr, _size)
#define func_free(_func, _ptr) (_func)(_ptr)
#endif

typedef void (*osips_mem_info_f) (void *block, struct mem_info *i);
typedef void (*osips_mem_status_f) (void *block);
typedef unsigned long (*osips_get_mmstat_f) (void *block);
Expand Down
1 change: 1 addition & 0 deletions mem/mem.h
Expand Up @@ -29,6 +29,7 @@
#include "../config.h"
#include "../dprint.h"

#include "func_mem.h"
#ifdef PKG_MALLOC
#include "common.h"

Expand Down
46 changes: 46 additions & 0 deletions mem/mem_funcs.h
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2019 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef func_mem_h
#define func_mem_h

#ifdef DBG_MALLOC
typedef void *(*osips_malloc_f) (unsigned long size,
const char *file, const char *func, unsigned int line);
typedef void *(*osips_realloc_f) (void *ptr, unsigned long size,
const char *file, const char *func, unsigned int line);
typedef void (*osips_free_f) (void *ptr,
const char *file, const char *func, unsigned int line);
#define func_malloc(_func, _size) (_func)(_size, \
__FILE__, __FUNCTION__, __LINE__ )
#define func_realloc(_func, _ptr, _size) (_func)(_ptr, _size, \
__FILE__, __FUNCTION__, __LINE__ )
#define func_free(_func, _ptr) (_func)(_ptr, \
__FILE__, __FUNCTION__, __LINE__ )
#else
typedef void *(*osips_malloc_f) (unsigned long size);
typedef void *(*osips_realloc_f) (void *ptr, unsigned long size);
typedef void (*osips_free_f) (void *ptr);
#define func_malloc(_func, _size) (_func)(_size)
#define func_realloc(_func, _ptr, _size) (_func)(_ptr, _size)
#define func_free(_func, _ptr) (_func)(_ptr)
#endif

#endif
1 change: 1 addition & 0 deletions mem/rpm_mem.h
Expand Up @@ -37,6 +37,7 @@
#include "../dprint.h"
#include "../globals.h"
#include "../lock_ops.h" /* we don't include locking.h on purpose */
#include "func_mem.h"
#include "common.h"

#include "../mi/mi.h"
Expand Down
1 change: 1 addition & 0 deletions mem/shm_mem.h
Expand Up @@ -48,6 +48,7 @@
#include "../dprint.h"
#include "../globals.h"
#include "../lock_ops.h" /* we don't include locking.h on purpose */
#include "func_mem.h"
#include "common.h"

#include "../mi/mi.h"
Expand Down

0 comments on commit e82dbde

Please sign in to comment.