Skip to content

Commit

Permalink
Do not duplicate code in destroy subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett McGrath committed Jul 11, 2019
1 parent f173602 commit efd3ab4
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions generic/zookeepertcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1921,29 +1921,8 @@ zootcl_delete_subcommand(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], ZO
int
zootcl_destroy_subcommand(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], ZOOAPI zhandle_t *zh, zootcl_objectClientData *zo)
{
// Close Zookeeper
zookeeper_close(zo->zh);
zo->zh = NULL;

// Remove the command exit handler and delete the command
Tcl_CmdInfo *infoPtr = (Tcl_CmdInfo *) ckalloc (sizeof (Tcl_CmdInfo));
infoPtr->deleteProc = NULL;
Tcl_SetCommandInfoFromToken(zo->cmdToken, infoPtr);
ckfree(infoPtr);
Tcl_DeleteCommandFromToken(interp, zo->cmdToken);

// Get rid of all event handlers and event sources
Tcl_DeleteExitHandler(zootcl_zookeeperObjectDelete, (ClientData)zo);
Tcl_DeleteThreadExitHandler(zootcl_zookeeperObjectDelete, (ClientData)zo);
if (zo->channel != NULL) {
Tcl_DeleteChannelHandler(zo->channel, zootcl_socket_ready, (ClientData)zo);
Tcl_DetachChannel(zo->interp, zo->channel);
}
Tcl_DeleteEventSource(zootcl_EventSetupProc, zootcl_EventCheckProc, (ClientData)zo);

// Free memory and get outta here
ckfree(zo);
return TCL_OK;
zootcl_zookeeperObjectDelete ((ClientData)zo);
return TCL_OK;
}

/*
Expand Down

0 comments on commit efd3ab4

Please sign in to comment.