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
012f4e29
Commit
012f4e29
authored
25 years ago
by
Kurt Zeilenga
Browse files
Options
Downloads
Patches
Plain Diff
Hide assert(p == NULL) behind LDAP_MEMORY_DEBUG.
Add detection for duplicate free in LDAP_MEMORY_DEBUG code.
parent
f257ee85
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libraries/liblber/io.c
+7
-0
7 additions, 0 deletions
libraries/liblber/io.c
libraries/liblber/lber-int.h
+1
-1
1 addition, 1 deletion
libraries/liblber/lber-int.h
libraries/liblber/memory.c
+62
-6
62 additions, 6 deletions
libraries/liblber/memory.c
with
70 additions
and
7 deletions
libraries/liblber/io.c
+
7
−
0
View file @
012f4e29
...
...
@@ -178,7 +178,14 @@ ber_realloc( BerElement *ber, unsigned long len )
void
ber_free
(
BerElement
*
ber
,
int
freebuf
)
{
#ifdef LDAP_MEMORY_DEBUG
assert
(
ber
!=
NULL
);
#endif
if
(
ber
==
NULL
)
{
return
;
}
assert
(
BER_VALID
(
ber
)
);
if
(
freebuf
&&
ber
->
ber_buf
!=
NULL
)
...
...
This diff is collapsed.
Click to expand it.
libraries/liblber/lber-int.h
+
1
−
1
View file @
012f4e29
...
...
@@ -201,7 +201,7 @@ extern BerMemoryFunctions* ber_int_memory_fns;
#define LBER_INT_FREE(p) ber_memfree((p))
#define LBER_INT_VFREE(v) ber_memvfree((void**)(v))
#define LBER_INT_STRDUP(s) ber_strdup((s))
#define LBER_MALLOC(s) ber_memalloc((s))
#define LBER_CALLOC(n,s) ber_memcalloc((n),(s))
#define LBER_REALLOC(p,s) ber_memrealloc((p),(s))
...
...
This diff is collapsed.
Click to expand it.
libraries/liblber/memory.c
+
62
−
6
View file @
012f4e29
...
...
@@ -12,28 +12,47 @@
#include
"lber-int.h"
#if
def
LDAP_MEMORY_DEBUG
#if LDAP_MEMORY_DEBUG
struct
ber_mem_hdr
{
union
bmu_align_u
{
size_t
bmu_size_t
;
void
*
bmu_voidp
;
double
bmu_double
;
long
bmu_long
;
char
bmu_char
[
4
];
}
ber_align
;
#define bm_junk ber_align.bmu_size_t
#define bm_data ber_align.bmu_char[1]
};
#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)
#endif
BerMemoryFunctions
*
ber_int_memory_fns
=
NULL
;
#if 0 && defined( LDAP_MEMORY_DEBUG )
void
ber_int_memfree( void **p )
{
assert( p != NULL );
assert( *p != BER_MEM_BADADDR );
ber_memfree( p );
*p = BER_MEM_BADADDR;
}
#endif
void
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
)
{
...
...
@@ -44,7 +63,9 @@ ber_memfree( void *p )
#ifdef LDAP_MEMORY_DEBUG
struct
ber_mem_hdr
*
mh
=
(
struct
ber_mem_hdr
*
)
((
char
*
)
p
-
sizeof
(
struct
ber_mem_hdr
));
assert
(
mh
->
bm_junk
==
BER_MEM_JUNK
);
assert
(
mh
->
bm_junk
==
BER_MEM_JUNK
);
mh
->
bm_junk
=
~
BER_MEM_JUNK
;
free
(
mh
);
#else
free
(
p
);
...
...
@@ -64,7 +85,13 @@ ber_memvfree( void **vec )
{
int
i
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
vec
!=
NULL
);
/* vec damn better point to something */
#endif
if
(
vec
==
NULL
)
{
return
;
}
for
(
i
=
0
;
vec
[
i
]
!=
NULL
;
i
++
)
{
LBER_FREE
(
vec
[
i
]
);
...
...
@@ -79,8 +106,10 @@ ber_memalloc( size_t s )
{
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
#ifdef LDAP_MEMORY_DEBUG
/* catch s == 0 when debugging */
assert
(
s
);
#endif
/* ignore s == 0 when not debugging */
if
(
s
==
0
)
{
...
...
@@ -112,8 +141,10 @@ ber_memcalloc( size_t n, size_t s )
{
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
#ifdef LDAP_MEMORY_DEBUG
/* catch s,n == 0 when debugging */
assert
(
n
&&
s
);
#endif
/* ignore s,n == 0 when not debugging */
if
(
n
==
0
||
s
==
0
)
{
...
...
@@ -166,6 +197,8 @@ ber_memrealloc( void* p, size_t s )
mh
=
p
;
assert
(
mh
->
bm_junk
==
BER_MEM_JUNK
);
return
&
mh
[
1
];
#else
return
realloc
(
p
,
s
);
...
...
@@ -181,7 +214,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
if
(
bv
==
NULL
)
{
return
;
}
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
...
...
@@ -197,7 +236,13 @@ ber_bvecfree( struct berval **bv )
{
int
i
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
bv
!=
NULL
);
/* bv damn better point to something */
#endif
if
(
bv
==
NULL
)
{
return
;
}
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
...
...
@@ -214,7 +259,9 @@ ber_bvdup(
{
struct
berval
*
new
;
assert
(
bv
!=
NULL
);
#ifdef LDAP_MEMORY_DEBUG
assert
(
bv
!=
NULL
);
/* bv damn better point to something */
#endif
ber_int_options
.
lbo_valid
=
LBER_INITIALIZED
;
...
...
@@ -222,7 +269,6 @@ ber_bvdup(
return
NULL
;
}
if
((
new
=
LBER_MALLOC
(
sizeof
(
struct
berval
)
))
==
NULL
)
{
return
NULL
;
}
...
...
@@ -246,10 +292,20 @@ ber_bvdup(
}
char
*
(
ber_strdup
)
(
LDAP_CONST
char
*
s
)
ber_strdup
(
LDAP_CONST
char
*
s
)
{
char
*
p
;
size_t
len
=
strlen
(
s
)
+
1
;
size_t
len
;
#ifdef LDAP_MEMORY_DEBUG
assert
(
s
!=
NULL
);
/* bv damn better point to something */
#endif
if
(
s
==
NULL
)
{
return
(
NULL
);
}
len
=
strlen
(
s
)
+
1
;
if
(
(
p
=
(
char
*
)
LBER_MALLOC
(
len
))
==
NULL
)
{
return
(
NULL
);
...
...
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