Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
28da89eb
Commit
28da89eb
authored
Nov 19, 2013
by
Thomas Jahns
🤸
Browse files
Fix resource deallocation.
parent
bb31da8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/namespace.c
View file @
28da89eb
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
/* PTHREAD_MUTEX_RECURSIVE */
#endif
#include
<limits.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
"cdi.h"
#include
"dmemory.h"
#include
"namespace.h"
...
...
@@ -63,13 +72,28 @@ static int namespacesSize = 1;
#if defined (HAVE_LIBPTHREAD)
# include <pthread.h>
static
pthread_mutex_t
namespaceMutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
pthread_once_t
namespaceOnce
=
PTHREAD_ONCE_INIT
;
static
pthread_mutex_t
namespaceMutex
;
static
void
namespaceInitialize
(
void
)
{
pthread_mutexattr_t
ma
;
pthread_mutexattr_init
(
&
ma
);
pthread_mutexattr_settype
(
&
ma
,
PTHREAD_MUTEX_RECURSIVE
);
pthread_mutex_init
(
&
namespaceMutex
,
&
ma
);
pthread_mutexattr_destroy
(
&
ma
);
}
# define NAMESPACE_LOCK() pthread_mutex_lock(&namespaceMutex)
# define NAMESPACE_UNLOCK() pthread_mutex_unlock(&namespaceMutex)
# define NAMESPACE_INIT() pthread_once(&namespaceOnce, \
namespaceInitialize)
#else
# define NAMESPACE_INIT() do { } while (0)
# define NAMESPACE_LOCK()
# define NAMESPACE_UNLOCK()
...
...
@@ -117,6 +141,7 @@ int
namespaceNew
()
{
int
newNamespaceID
=
-
1
;
NAMESPACE_INIT
();
NAMESPACE_LOCK
();
if
(
namespacesSize
>
nNamespaces
)
{
...
...
@@ -165,6 +190,7 @@ namespaceNew()
void
namespaceDelete
(
int
namespaceID
)
{
NAMESPACE_INIT
();
NAMESPACE_LOCK
();
xassert
(
namespaceID
<
namespacesSize
&&
nNamespaces
);
reshListDestruct
(
namespaceID
);
...
...
@@ -173,18 +199,6 @@ namespaceDelete(int namespaceID)
NAMESPACE_UNLOCK
();
}
void
namespaceCleanup
(
void
)
{
if
(
nNamespaces
>
1
)
{
initialNamespace
=
namespaces
[
0
];
free
(
namespaces
);
namespaces
=
&
initialNamespace
;
nNamespaces
=
1
;
}
}
int
namespaceGetNumber
()
{
return
nNamespaces
;
...
...
@@ -267,10 +281,16 @@ union namespaceSwitchValue namespaceSwitchGet(enum namespaceSwitch sw)
void
cdiReset
(
void
)
{
NAMESPACE_INIT
();
NAMESPACE_LOCK
();
for
(
int
namespaceID
=
0
;
namespaceID
<
namespacesSize
;
++
namespaceID
)
namespaceDelete
(
namespaceID
);
namespaces
=
&
initialNamespace
;
if
(
namespaces
[
namespaceID
].
resStage
!=
STAGE_UNUSED
)
namespaceDelete
(
namespaceID
);
if
(
namespaces
!=
&
initialNamespace
)
{
free
(
namespaces
);
namespaces
=
&
initialNamespace
;
}
namespacesSize
=
1
;
nNamespaces
=
1
;
activeNamespace
=
0
;
...
...
src/resource_handle.c
View file @
28da89eb
...
...
@@ -150,6 +150,7 @@ static void listDestroy ( void )
namespaceDelete
(
i
);
free
(
resHList
);
resHList
=
NULL
;
cdiReset
();
LIST_UNLOCK
();
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment