@@ -48,6 +48,7 @@ struct DatareqCmd {
48
48
static struct HashTable * xdrCommandHash = NULL ;
49
49
static struct DatareqCmd * xdrDatareqList = NULL ;
50
50
static struct HashTable * xdrErrorHash = NULL ;
51
+ static int cleanup_reg = 0 ;
51
52
52
53
/// Value in the PROT element in the CMD structure that indicates protected cmd
53
54
#define CMD_PROTECTED 1
@@ -108,6 +109,25 @@ static void fakeStatusCommand(int socket, unsigned char cmd, void * data,
108
109
109
110
static ProcessData * cmdGProc = NULL ;
110
111
112
+ static void CMD_hash_cleanup (void )
113
+ {
114
+ struct DatareqCmd * node ;
115
+ cleanup_reg = 0 ;
116
+
117
+ if (xdrCommandHash )
118
+ HASH_free_table (xdrCommandHash );
119
+ xdrCommandHash = NULL ;
120
+
121
+ if (xdrErrorHash )
122
+ HASH_free_table (xdrErrorHash );
123
+ xdrErrorHash = NULL ;
124
+
125
+ while ((node = xdrDatareqList )) {
126
+ xdrDatareqList = node -> next ;
127
+ free (node );
128
+ }
129
+ }
130
+
111
131
void heartbeat_populator (void * arg , XDR_tx_struct cb , void * cb_args )
112
132
{
113
133
struct CommandCbArg * cmds = (struct CommandCbArg * )arg ;
@@ -1074,6 +1094,10 @@ void CMD_register_command(struct CMD_XDRCommandInfo *cmd, int override)
1074
1094
1075
1095
if (cmd -> command ) {
1076
1096
if (!xdrCommandHash ) {
1097
+ if (!cleanup_reg )
1098
+ atexit (& CMD_hash_cleanup );
1099
+ cleanup_reg = 1 ;
1100
+
1077
1101
xdrCommandHash = HASH_create_table (37 , & xdr_cmd_hash_func ,
1078
1102
& xdr_cmd_cmp_key , & xdr_cmd_key_for_data );
1079
1103
if (!xdrCommandHash )
@@ -1082,6 +1106,10 @@ void CMD_register_command(struct CMD_XDRCommandInfo *cmd, int override)
1082
1106
table = xdrCommandHash ;
1083
1107
}
1084
1108
else if (cmd -> types ) {
1109
+ if (!cleanup_reg )
1110
+ atexit (& CMD_hash_cleanup );
1111
+ cleanup_reg = 1 ;
1112
+
1085
1113
node = malloc (sizeof (* node ));
1086
1114
if (!node )
1087
1115
return ;
@@ -1091,6 +1119,7 @@ void CMD_register_command(struct CMD_XDRCommandInfo *cmd, int override)
1091
1119
1092
1120
if (cmd -> params )
1093
1121
cmd -> parameter = XDR_definition_for_type (cmd -> params );
1122
+
1094
1123
return ;
1095
1124
}
1096
1125
else
@@ -1140,6 +1169,10 @@ void CMD_register_error(struct CMD_ErrorInfo *err)
1140
1169
return ;
1141
1170
1142
1171
if (!xdrErrorHash ) {
1172
+ if (!cleanup_reg )
1173
+ atexit (& CMD_hash_cleanup );
1174
+ cleanup_reg = 1 ;
1175
+
1143
1176
xdrErrorHash = HASH_create_table (37 , & xdr_err_hash_func ,
1144
1177
& xdr_err_cmp_key , & xdr_err_key_for_data );
1145
1178
if (!xdrErrorHash )
0 commit comments