Make use of a talloc_destructor for free_eventlog_info()
authorVolker Lendecke <vl@samba.org>
Wed, 7 Jan 2009 16:56:08 +0000 (17:56 +0100)
committerVolker Lendecke <vl@samba.org>
Thu, 8 Jan 2009 21:29:53 +0000 (22:29 +0100)
source3/rpc_server/srv_eventlog_nt.c

index e5be325a16c2f7651d678bad571d643d6343780f..7b7f381d91be81f248eb7d68fe02dbe449afc032 100644 (file)
@@ -37,14 +37,17 @@ typedef struct {
 /********************************************************************
  ********************************************************************/
 
-static void free_eventlog_info( void *ptr )
+static int eventlog_info_destructor(EVENTLOG_INFO *elog)
 {
-       EVENTLOG_INFO *elog = (EVENTLOG_INFO *)ptr;
-
-       if ( elog->etdb )
-               elog_close_tdb( elog->etdb, False );
+       if (elog->etdb) {
+               elog_close_tdb(elog->etdb, false);
+       }
+       return 0;
+}
 
-       TALLOC_FREE( elog );
+static void free_eventlog_info( void *ptr )
+{
+       TALLOC_FREE(ptr);
 }
 
 /********************************************************************
@@ -186,6 +189,7 @@ static NTSTATUS elog_open( pipes_struct * p, const char *logname, POLICY_HND *hn
 
        if ( !(elog = TALLOC_ZERO_P( NULL, EVENTLOG_INFO )) )
                return NT_STATUS_NO_MEMORY;
+       talloc_set_destructor(elog, eventlog_info_destructor);
 
        elog->logname = talloc_strdup( elog, logname );
 
@@ -228,7 +232,6 @@ static NTSTATUS elog_open( pipes_struct * p, const char *logname, POLICY_HND *hn
        /* now do the access check.  Close the tdb if we fail here */
 
        if ( !elog_check_access( elog, p->server_info->ptok ) ) {
-               elog_close_tdb( elog->etdb, False );
                TALLOC_FREE( elog );
                return NT_STATUS_ACCESS_DENIED;
        }