3 Replies Latest reply: Jun 18, 2014 10:22 PM by Winter Zhang RSS

    Is there a bug in env_open.c?

    compmaniak

      Hello,

      I use Berkeley DB 6.0.30 as a static library built with multi byte character set + debug runtime dll (MSVS 2010). Suddenly I have faced with a problem when closing Berkeley environment in panic state. When PANIC_ISSET returns true an access violation is occured in ENV_LEAVE statement.

      Here is the code from __env_close_pp function from env_open.c

       

      if (PANIC_ISSET(env)) {
          flags_orig = dbenv->flags;
          F_SET(dbenv, DB_ENV_NOPANIC);
          ENV_ENTER(env, ip);
          /* clean up from registry file */
          if (dbenv->registry != NULL) {
              /*
               * Temporarily set no panic so we do not trigger the
               * LAST_PANIC_CHECK_BEFORE_IO check in __os_physwrite
               * thus allowing the unregister to happen correctly.
               */
              (void)__envreg_unregister(env, 0);
              dbenv->registry = NULL;
          }

       

          /* Close all underlying threads and sockets. */
          (void)__repmgr_close(env);

       

          /* Close all underlying file handles. */
          (void)__file_handle_cleanup(env);
          dbenv->flags = flags_orig;
          (void)__env_region_cleanup(env);
          ENV_LEAVE(env, ip);

       

          return (__env_panic_msg(env));
      }

       

      ENV_LEAVE statement is executed after detaching from shared regions. Thus the memory pointed by 'ip' becomes invalid and an access violation is occured. I simply placed ENV_LEAVE statement before clearing the resources and this solved my problem.

       

      ENV_LEAVE(env, ip);

      /* Close all underlying file handles. */

      (void)__file_handle_cleanup(env);

      dbenv->flags = flags_orig;

      (void)__env_region_cleanup(env);

       

      Is it a bug or something wrong?

      I couldn't find Berkeley issue tracker so I placed the message here. Thanks.