author | Alberto Bertogli
<albertito@gmail.com> 2004-11-28 15:20:16 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-07-15 13:47:19 UTC |
parent | 7776533fc6c22a3f36b50d17a5ee200ebd3f1d51 |
trans.c | +9 | -1 |
diff --git a/trans.c b/trans.c index 7ee2978..688594d 100644 --- a/trans.c +++ b/trans.c @@ -167,14 +167,22 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset) tmpop->next->prev = tmpop; jop = tmpop->next; } - pthread_mutex_unlock(&(ts->lock)); jop->buf = malloc(count); if (jop->buf == NULL) { + /* remove from the list and fail */ + if (jop->prev == NULL) { + ts->op = NULL; + } else { + jop->prev->next = jop->next; + } free(jop); + pthread_mutex_unlock(&(ts->lock)); return 0; } + pthread_mutex_unlock(&(ts->lock)); + /* we copy the buffer because then the caller can reuse it */ memcpy(jop->buf, buf, count); jop->len = count;