apache "Fail to reuse existing cache

If the shared memory feature is enabled, it can reuse an existing shared memory file segment if it was already created, possibly by another process. The apr_shm_create command returns a code that can be used to verify if an existing sm file segment already exists or not."
Bug fixed by commit 97ecbec1237
Type BehaviorViolation
Config "APU_HAS_LDAP && APR_HAS_SHARED_MEMORY" (2nd degree)
Fix-in code
Location modules/experimental/
#include <stdlib.h>

#define APR_SUCCESS 1
#define EEXIST 2

int *cache = NULL;
int *util_ldap_shm;

int apr_shm_attach(int **util_ldap_shm)
{
  if (cache) {
    *util_ldap_shm = cache;
    return 0;
  }
  return -1;
}

int apr_shm_create(int **util_ldap_shm)
{
  if (cache)
    return EEXIST;
  cache = malloc(sizeof(int));
  *util_ldap_shm = cache;
  return 0;
}

int util_ldap_cache_init()
{
#if APR_HAS_SHARED_MEMORY
  int result = apr_shm_create(&util_ldap_shm);
  if (result != APR_SUCCESS) {
    return result;
  }
#endif
  return APR_SUCCESS;
}

int main(void)
{
  if (rand() % 2) {
    cache = malloc(sizeof(int));
  }
  util_ldap_cache_init();
  return 0;
}
diff --git a/apache/simple/97ecbec.c b/apache/simple/97ecbec.c
--- a/apache/simple/97ecbec.c
+++ b/apache/simple/97ecbec.c
@@ -28,6 +28,9 @@ int util_ldap_cache_init()
 {
 #if APR_HAS_SHARED_MEMORY
   int result = apr_shm_create(&util_ldap_shm);
+  if (result == EEXIST) {
+    result = apr_shm_attach(&util_ldap_shm);
+  }
   if (result != APR_SUCCESS) {
     return result;
   }
. call modules/experimental/util_ldap_cache.c:293:  apr_status_t util_ldap_cache_init()
. modules/experimental/util_ldap_cache.c:298: result = apr_shm_create(&util_ldap_shm, reqsize, "/tmp/ldap_cache", pool);
. modules/experimental/util_ldap_cache.c:299: if (result != APR_SUCCESS) {
. // if a cache has been created already (result == EEXIST) it will not be used
. ERROR modules/experimental/util_ldap_cache.c:300: return result;