Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenLDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Nadezhda Ivanova
OpenLDAP
Commits
b09e658d
Commit
b09e658d
authored
25 years ago
by
Kurt Zeilenga
Browse files
Options
Downloads
Patches
Plain Diff
Add and use a BER_MEM_VALID macro (behind ifdef LDAP_MEMORY_DEBUG).
Make sure LBER_INTIALIZED is set on any ber_mem* call.
parent
012f4e29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/liblber/memory.c
+25
-22
25 additions, 22 deletions
libraries/liblber/memory.c
with
25 additions
and
22 deletions
libraries/liblber/memory.c
+
25
−
22
View file @
b09e658d
...
...
@@ -27,6 +27,12 @@ struct ber_mem_hdr {
#define BER_MEM_JUNK 0xddeeddeeU
static
const
struct
ber_mem_hdr
ber_int_mem_hdr
=
{
BER_MEM_JUNK
};
#define BER_MEM_BADADDR ((void *) &ber_int_mem_hdr.bm_data)
#define BER_MEM_VALID(p) do { \
assert( (p) != BER_MEM_BADADDR ); \
assert( (p) != (void *) &ber_int_mem_hdr ); \
} while(1)
#else
#define BER_MEM_VALID(p)
/* no-op */
#endif
BerMemoryFunctions
*
ber_int_memory_fns
=
NULL
;
...
...
@@ -36,7 +42,7 @@ void
ber_int_memfree( void **p )
{
assert( p != NULL );
assert( *p != BER_MEM_BADADDR
)
;
BER_MEM_VALID( *p
)
ber_memfree( p );
...
...
@@ -49,16 +55,13 @@ ber_memfree( void *p )
{
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
#ifdef LDAP_MEMORY_DEBUG
/* catch p == NULL when debugging */
assert
(
p
!=
NULL
);
#endif
/* ignore p == NULL when not debugging */
if
(
p
==
NULL
)
{
return
;
}
BER_MEM_VALID
(
p
)
if
(
ber_int_memory_fns
==
NULL
)
{
#ifdef LDAP_MEMORY_DEBUG
struct
ber_mem_hdr
*
mh
=
(
struct
ber_mem_hdr
*
)
...
...
@@ -85,14 +88,14 @@ ber_memvfree( void **vec )
{
int
i
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
vec
!=
NULL
);
/* vec damn better point to something */
#endif
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
if
(
vec
==
NULL
)
{
return
;
}
BER_MEM_VALID
(
vec
)
for
(
i
=
0
;
vec
[
i
]
!=
NULL
;
i
++
)
{
LBER_FREE
(
vec
[
i
]
);
}
...
...
@@ -124,6 +127,7 @@ ber_memalloc( size_t s )
mh
->
bm_junk
=
BER_MEM_JUNK
;
BER_MEM_VALID
(
&
mh
[
1
]
)
return
&
mh
[
1
];
#else
return
malloc
(
s
);
...
...
@@ -157,6 +161,8 @@ ber_memcalloc( size_t n, size_t s )
(
n
*
s
)
+
sizeof
(
struct
ber_mem_hdr
)
);
mh
->
bm_junk
=
BER_MEM_JUNK
;
BER_MEM_VALID
(
&
mh
[
1
]
)
return
&
mh
[
1
];
#else
return
calloc
(
n
,
s
);
...
...
@@ -185,6 +191,8 @@ ber_memrealloc( void* p, size_t s )
return
NULL
;
}
BER_MEM_VALID
(
p
)
if
(
ber_int_memory_fns
==
NULL
)
{
#ifdef LDAP_MEMORY_DEBUG
struct
ber_mem_hdr
*
mh
=
(
struct
ber_mem_hdr
*
)
...
...
@@ -199,6 +207,7 @@ ber_memrealloc( void* p, size_t s )
assert
(
mh
->
bm_junk
==
BER_MEM_JUNK
);
BER_MEM_VALID
(
&
mh
[
1
]
)
return
&
mh
[
1
];
#else
return
realloc
(
p
,
s
);
...
...
@@ -214,15 +223,13 @@ ber_memrealloc( void* p, size_t s )
void
ber_bvfree
(
struct
berval
*
bv
)
{
#ifdef LDAP_MEMORY_DEBUG
assert
(
bv
!=
NULL
);
/* bv damn better point to something */
#endif
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
if
(
bv
==
NULL
)
{
return
;
}
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
BER_MEM_VALID
(
bv
)
if
(
bv
->
bv_val
!=
NULL
)
LBER_FREE
(
bv
->
bv_val
);
...
...
@@ -236,15 +243,13 @@ ber_bvecfree( struct berval **bv )
{
int
i
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
bv
!=
NULL
);
/* bv damn better point to something */
#endif
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
if
(
bv
==
NULL
)
{
return
;
}
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
BER_MEM_VALID
(
bv
)
for
(
i
=
0
;
bv
[
i
]
!=
NULL
;
i
++
)
ber_bvfree
(
bv
[
i
]
);
...
...
@@ -259,10 +264,6 @@ ber_bvdup(
{
struct
berval
*
new
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
bv
!=
NULL
);
/* bv damn better point to something */
#endif
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
if
(
bv
==
NULL
)
{
...
...
@@ -297,6 +298,8 @@ ber_strdup( LDAP_CONST char *s )
char
*
p
;
size_t
len
;
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
s
!=
NULL
);
/* bv damn better point to something */
#endif
...
...
@@ -313,4 +316,4 @@ ber_strdup( LDAP_CONST char *s )
SAFEMEMCPY
(
p
,
s
,
len
);
return
(
p
);
}
\ No newline at end of file
}
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