Skip to content

Commit

Permalink
fixed all the issues reported by the clang static analyzer
Browse files Browse the repository at this point in the history
some potential leaks and one potential access to freed memory
  • Loading branch information
xant committed Jan 9, 2014
1 parent b32ae8e commit 004ee97
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ void ht_clear(hashtable_t *table) {
SPIN_LOCK(&table->lock);
for (i = 0; i < table->size; i++) {
ht_item_t *item = NULL;
ht_item_t *tmp;

ht_items_list_t *list = __sync_fetch_and_add(&table->items[i], 0);

if (!list)
continue;

while((item = TAILQ_FIRST(&list->head))) {
TAILQ_FOREACH_SAFE(item, &list->head, next, tmp) {
TAILQ_REMOVE(&list->head, item, next);
if (table->free_item_cb)
table->free_item_cb(item->data);
Expand Down Expand Up @@ -246,6 +247,9 @@ int _ht_set_internal(hashtable_t *table, void *key, size_t klen,
void *prev = NULL;
size_t plen = 0;

if (!klen)
return -1;

PERL_HASH(hash, key, klen);

actual_size = table->size;
Expand Down Expand Up @@ -547,6 +551,8 @@ void *_ht_get_internal(hashtable_t *table, void *key, size_t klen,
}
if (dlen)
*dlen = item->dlen;

break;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/rbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ rbuf_read_until(rbuf_t *rb, u_char octet, u_char *out, int maxsize)
for (i = 0; to_read > 0 && (size-to_read) < maxsize; i++) {
to_read--;
if(rb->buf[i] == octet) {
found = 1;
break;
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/refcnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ refcnt_node_t *deref_link(refcnt_t *refcnt, refcnt_node_t **link) {
}

void release_ref(refcnt_t *refcnt, refcnt_node_t *ref) {
if (!refcnt)
return;

if (ATOMIC_READ(ref->count) > 0)
ATOMIC_DECREMENT(ref->count, 1);
if (ATOMIC_CMPXCHG(ref->delete, 0, 1)) {
Expand Down
5 changes: 5 additions & 0 deletions src/rqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ rqueue_t *rqueue_create(uint32_t size, rqueue_mode_t mode) {
rb->tail = page;
}

if (!rb->head || !rb->tail) {
free(rb);
return NULL;
}

// close the ringbuffer
rb->head->prev = rb->tail;
rb->tail->next = rb->head;
Expand Down

0 comments on commit 004ee97

Please sign in to comment.