<commit_before>/* Copyright (C) 2000 MySQL AB, 2011 Monty Program Ab

   This program 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; version 2 of the License.

   This program 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 St, Fifth Floor, Boston, MA 02110-1301  USA */

/********************************************************************
  memory debugger
  based on safemalloc, memory sub-system, written by <NAME>
********************************************************************/


#include "mysys_priv.h"
#include <my_stacktrace.h>      /* my_addr_resolve */

#if HAVE_EXECINFO_H
#include <execinfo.h>
#endif

/*
  this can be set to 1 if we leak memory and know it
  (to disable memory leak tests on exit)
*/
int sf_leaking_memory= 0;

#ifdef SAFEMALLOC

/* this mutex protects all sf_* variables, and nothing else*/
static pthread_mutex_t sf_mutex;
static int init_done= 0;

#ifndef SF_REMEMBER_FRAMES
#define SF_REMEMBER_FRAMES 8
#endif

/* ignore the first two frames (sf_malloc itself, and my_malloc) */
#define SF_FRAMES_SKIP          2

/*
  Structure that stores information of an allocated memory block
  The data is at &struct_adr+sizeof(struct irem)
  Note that sizeof(struct st_irem) % sizeof(double) == 0
*/
struct st_irem
{
  struct st_irem *next;        /* Linked list of structures       */
  struct st_irem *prev;        /* Other link                      */
  size_t datasize;             /* Size requested                  */
#ifdef HAVE_BACKTRACE
  void *frame[SF_REMEMBER_FRAMES]; /* call stack                  */
#endif
  uint32 flags;                /* Flags passed to malloc 	  */
  my_thread_id thread_id;      /* Which thread did the allocation */
  uint32 marker;               /* Underrun marker value           */
};

static int    sf_malloc_count= 0;              /* Number of allocated chunks */

static void  *sf_min_adress= (void*) (intptr)~0ULL,
             *sf_max_adress= 0;

static struct st_irem *sf_malloc_root = 0;

#define MAGICSTART      0x14235296      /* A magic value for underrun key */

#define MAGICEND0       0x68            /* Magic values for overrun keys  */
#define MAGICEND1       0x34            /*              "                 */
#define MAGICEND2       0x7A            /*              "                 */
#define MAGICEND3       0x15            /*              "                 */

static int bad_ptr(const char *where, void *ptr);
static void free_memory(void *ptr);
static void sf_terminate();<commit_msg>Fixed compilarion failure on 32bit systems<commit_after>/* Copyright (C) 2000 MySQL AB, 2011 Monty Program Ab

   This program 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; version 2 of the License.

   This program 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 St, Fifth Floor, Boston, MA 02110-1301  USA */

/********************************************************************
  memory debugger
  based on safemalloc, memory sub-system, written by <NAME>
********************************************************************/


#include "mysys_priv.h"
#include <my_stacktrace.h>      /* my_addr_resolve */

#if HAVE_EXECINFO_H
#include <execinfo.h>
#endif

/*
  this can be set to 1 if we leak memory and know it
  (to disable memory leak tests on exit)
*/
int sf_leaking_memory= 0;

#ifdef SAFEMALLOC

/* this mutex protects all sf_* variables, and nothing else*/
static pthread_mutex_t sf_mutex;
static int init_done= 0;

#ifndef SF_REMEMBER_FRAMES
#define SF_REMEMBER_FRAMES 8
#endif

/* ignore the first two frames (sf_malloc itself, and my_malloc) */
#define SF_FRAMES_SKIP          2

/*
  Structure that stores information of an allocated memory block
  The data is at &struct_adr+sizeof(struct irem)
  Note that sizeof(struct st_irem) % sizeof(double) == 0
*/
struct st_irem
{
  struct st_irem *next;        /* Linked list of structures       */
  struct st_irem *prev;        /* Other link                      */
  size_t datasize;             /* Size requested                  */
#if SIZEOF_SIZE_T == 4
  size_t pad;                  /* Compensate 32bit datasize */
#endif
#ifdef HAVE_BACKTRACE
  void *frame[SF_REMEMBER_FRAMES]; /* call stack                  */
#endif
  uint32 flags;                /* Flags passed to malloc 	  */
  my_thread_id thread_id;      /* Which thread did the allocation */
  uint32 marker;               /* Underrun marker value           */
};

static int    sf_malloc_count= 0;              /* Number of allocated chunks */

static void  *sf_min_adress= (void*) (intptr)~0ULL,
             *sf_max_adress= 0;

static struct st_irem *sf_malloc_root = 0;

#define MAGICSTART      0x14235296      /* A magic value for underrun key */

#define MAGICEND0       0x68            /* Magic values for overrun keys  */
#define MAGICEND1       0x34            /*              "                 */
#define MAGICEND2       0x7A            /*              "                 */
#define MAGICEND3       0x15            /*              "                 */

static int bad_ptr(const char *where, void *ptr);
static void free_memory(void *ptr);
static void sf_terminate();
{'fraction_non_alphanumeric': 0.11434753661784287, 'fraction_numerical': 0.020139813581890813, 'mean_word_length': 2.51198129748685, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581553', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1631, 'n_words': 649}