Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
08bd96c4
Commit
08bd96c4
authored
27 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
more DEBUG_MALLOC options added
Rev: src/pike_memory.c:1.24
parent
a28dd233
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pike_memory.c
+35
-15
35 additions, 15 deletions
src/pike_memory.c
with
35 additions
and
15 deletions
src/pike_memory.c
+
35
−
15
View file @
08bd96c4
...
...
@@ -9,7 +9,7 @@
#include
"pike_macros.h"
#include
"gc.h"
RCSID
(
"$Id: pike_memory.c,v 1.2
3
1998/04/
17 17:17:39
hubbe Exp $"
);
RCSID
(
"$Id: pike_memory.c,v 1.2
4
1998/04/
24 00:02:45
hubbe Exp $"
);
/* strdup() is used by several modules, so let's provide it */
#ifndef HAVE_STRDUP
...
...
@@ -461,6 +461,7 @@ static struct memhdr *find_memhdr(void *p);
int
verbose_debug_malloc
=
0
;
int
verbose_debug_exit
=
1
;
int
debug_malloc_check_all
=
0
;
#define HSIZE 1109891
#define LHSIZE 1109891
...
...
@@ -510,7 +511,7 @@ static struct memhdr no_leak_memlocs;
static
int
file_location_number
=
0
;
#if DEBUG_MALLOC_PAD - 0 > 0
char
*
do_pad
(
char
*
mem
,
size_t
size
)
char
*
do_pad
(
char
*
mem
,
long
size
)
{
long
q
,
e
;
mem
+=
DEBUG_MALLOC_PAD
;
...
...
@@ -529,18 +530,22 @@ char *do_pad(char *mem, size_t size)
return
mem
;
}
void
check_pad
(
struct
memhdr
*
mh
)
void
check_pad
(
struct
memhdr
*
mh
,
int
freeok
)
{
long
q
,
e
;
char
*
mem
=
mh
->
data
;
size_t
size
;
if
(
mh
->
size
<
0
)
long
size
=
mh
->
size
;
if
(
size
<
0
)
{
fprintf
(
stderr
,
"Freeing block %p twice (size %ld)!
\n
"
,
mem
,
~
mh
->
size
);
if
(
!
freeok
)
{
fprintf
(
stderr
,
"Access to free block: %p (size %ld)!
\n
"
,
mem
,
~
mh
->
size
);
dump_memhdr_locations
(
mh
,
0
);
abort
();
}
else
{
size
=
~
size
;
}
}
size
=
mh
->
size
;
q
=
(((
long
)
mem
)
^
0x555555
)
+
(
size
*
9248339
);
/* fprintf(stderr,"Checking %p(%d) %ld\n",mem, size, q); */
...
...
@@ -551,13 +556,13 @@ void check_pad(struct memhdr *mh)
q
=
(
q
<<
13
)
^
~
(
q
>>
5
);
if
(
mem
[
e
-
DEBUG_MALLOC_PAD
]
!=
tmp
)
{
fprintf
(
stderr
,
"Pre-padding overwritten for block at %p (size %d) (e=%ld %d!=%d)!
\n
"
,
mem
,
size
,
e
,
tmp
,
mem
[
e
-
DEBUG_MALLOC_PAD
]);
fprintf
(
stderr
,
"Pre-padding overwritten for block at %p (size %
l
d) (e=%ld %d!=%d)!
\n
"
,
mem
,
size
,
e
,
tmp
,
mem
[
e
-
DEBUG_MALLOC_PAD
]);
dump_memhdr_locations
(
mh
,
0
);
abort
();
}
if
(
mem
[
size
+
e
]
!=
tmp
)
{
fprintf
(
stderr
,
"Post-padding overwritten for block at %p (size %d) (e=%ld %d!=%d)!
\n
"
,
mem
,
size
,
e
,
tmp
,
mem
[
e
-
DEBUG_MALLOC_PAD
]);
fprintf
(
stderr
,
"Post-padding overwritten for block at %p (size %
l
d) (e=%ld %d!=%d)!
\n
"
,
mem
,
size
,
e
,
tmp
,
mem
[
e
-
DEBUG_MALLOC_PAD
]);
dump_memhdr_locations
(
mh
,
0
);
abort
();
}
...
...
@@ -566,7 +571,7 @@ void check_pad(struct memhdr *mh)
}
#else
#define do_pad(X,Y) (X)
#define check_pad(M)
#define check_pad(M
,X
)
#endif
static
int
location_number
(
const
char
*
file
,
int
line
)
...
...
@@ -660,7 +665,22 @@ BLOCK_ALLOC(memhdr,16382)
static
struct
memhdr
*
find_memhdr
(
void
*
p
)
{
struct
memhdr
*
mh
,
**
prev
;
unsigned
long
h
=
(
long
)
p
;
unsigned
long
h
;
#if DEBUG_MALLOC_PAD - 0 > 0
if
(
debug_malloc_check_all
)
{
for
(
h
=
0
;
h
<
HSIZE
;
h
++
)
{
for
(
mh
=
hash
[
h
];
mh
;
mh
=
mh
->
next
)
{
check_pad
(
mh
,
1
);
}
}
}
#endif
h
=
(
long
)
p
;
h
%=
HSIZE
;
for
(
prev
=
hash
+
h
;
(
mh
=*
prev
);
prev
=&
mh
->
next
)
{
...
...
@@ -669,7 +689,7 @@ static struct memhdr *find_memhdr(void *p)
*
prev
=
mh
->
next
;
mh
->
next
=
hash
[
h
];
hash
[
h
]
=
mh
;
check_pad
(
mh
);
check_pad
(
mh
,
0
);
return
mh
;
}
}
...
...
@@ -760,7 +780,7 @@ static int remove_memhdr(void *p, int already_gone)
if
(
mh
->
data
==
p
)
{
if
(
mh
->
size
<
0
)
mh
->
size
=~
mh
->
size
;
if
(
!
already_gone
)
check_pad
(
mh
);
if
(
!
already_gone
)
check_pad
(
mh
,
0
);
*
prev
=
mh
->
next
;
low_add_marks_to_memhdr
(
&
no_leak_memlocs
,
mh
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment