Don't use key member of dictionary iter objects after deletion

This commit is contained in:
Elizabeth Myers 2016-04-12 09:43:50 -05:00
parent 9e5c31ea0d
commit 4f2b9a4fd1
No known key found for this signature in database
GPG key ID: 1A10EF78D83E317B
2 changed files with 5 additions and 1 deletions

View file

@ -32,6 +32,7 @@
struct BlacklistStats struct BlacklistStats
{ {
char *host;
uint8_t iptype; uint8_t iptype;
unsigned int hits; unsigned int hits;
}; };

View file

@ -562,6 +562,7 @@ add_blacklist(const char *host, const char *reason, uint8_t iptype, rb_dlink_lis
if(s) if(s)
filterbuf[s - 1] = '\0'; filterbuf[s - 1] = '\0';
stats->host = rb_strdup(host);
stats->iptype = iptype; stats->iptype = iptype;
stats->hits = 0; stats->hits = 0;
rb_dictionary_add(bl_stats, host, stats); rb_dictionary_add(bl_stats, host, stats);
@ -577,6 +578,7 @@ del_blacklist(const char *host)
if(stats != NULL) if(stats != NULL)
{ {
rb_dictionary_delete(bl_stats, host); rb_dictionary_delete(bl_stats, host);
rb_free(stats->host);
rb_free(stats); rb_free(stats);
} }
@ -592,8 +594,9 @@ del_blacklist_all(void)
RB_DICTIONARY_FOREACH(stats, &iter, bl_stats) RB_DICTIONARY_FOREACH(stats, &iter, bl_stats)
{ {
rb_dictionary_delete(bl_stats, stats->host);
rb_free(stats->host);
rb_free(stats); rb_free(stats);
rb_dictionary_delete(bl_stats, iter.cur->key);
} }
rb_helper_write(authd_helper, "O rbl_del_all"); rb_helper_write(authd_helper, "O rbl_del_all");