summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/mh/mailmh.c
authorzautrix <zautrix>2005-01-24 21:00:03 (UTC)
committer zautrix <zautrix>2005-01-24 21:00:03 (UTC)
commit60733d98dff3ff5f8e95c514af258498aa7aa014 (patch) (side-by-side diff)
tree751d6533a51790da2afa49c870ff2342d6e3b0bf /kmicromail/libetpan/mh/mailmh.c
parentbb33b559609356149ae51cb50c081b3e82aecafb (diff)
downloadkdepimpi-60733d98dff3ff5f8e95c514af258498aa7aa014.zip
kdepimpi-60733d98dff3ff5f8e95c514af258498aa7aa014.tar.gz
kdepimpi-60733d98dff3ff5f8e95c514af258498aa7aa014.tar.bz2
memory leak fix
Diffstat (limited to 'kmicromail/libetpan/mh/mailmh.c') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/mh/mailmh.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/kmicromail/libetpan/mh/mailmh.c b/kmicromail/libetpan/mh/mailmh.c
index 1087ce1..2d1f26d 100644
--- a/kmicromail/libetpan/mh/mailmh.c
+++ b/kmicromail/libetpan/mh/mailmh.c
@@ -828,163 +828,166 @@ int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
mailmh_msg_info_free(msg_info);
error = MAILMH_ERROR_MEMORY;
goto err;
}
return MAILMH_NO_ERROR;
free:
free(tmpname);
err:
return error;
}
int mailmh_folder_add_message(struct mailmh_folder * folder,
const char * message, size_t size)
{
return mailmh_folder_add_message_uid(folder, message, size, NULL);
}
int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
int fd, uint32_t * pindex)
{
char * message;
struct stat buf;
int r;
#if 0
r = mailmh_folder_update(folder);
if (r != MAILMH_NO_ERROR)
return r;
#endif
if (fstat(fd, &buf) == -1)
return MAILMH_ERROR_FILE;
message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (message == MAP_FAILED)
return MAILMH_ERROR_FILE;
r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex);
munmap(message, buf.st_size);
return r;
}
int mailmh_folder_add_message_file(struct mailmh_folder * folder,
int fd)
{
return mailmh_folder_add_message_file_uid(folder, fd, NULL);
}
int mailmh_folder_remove_message(struct mailmh_folder * folder,
uint32_t index)
{
char * filename;
struct mailmh_msg_info * msg_info;
int res;
int r;
chashdatum key;
chashdatum data;
#if 0
r = mailmh_folder_update(folder);
if (r != MAILMH_NO_ERROR) {
res = r;
goto err;
}
#endif
r = mailmh_folder_get_message_filename(folder, index, &filename);
if (filename == NULL) {
res = r;
goto err;
}
if (unlink(filename) == -1) {
res = MAILMH_ERROR_FILE;
goto free;
}
key.data = &index;
key.len = sizeof(index);
r = chash_get(folder->fl_msgs_hash, &key, &data);
#if 0
msg_info = cinthash_find(folder->fl_msgs_hash, index);
#endif
if (r == 0) {
msg_info = data.data;
carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
#if 0
cinthash_remove(folder->fl_msgs_hash, index);
#endif
chash_delete(folder->fl_msgs_hash, &key, NULL);
}
+ // LR
+ mailmh_msg_info_free( msg_info );
+ free(filename);
return MAILMH_NO_ERROR;
free:
free(filename);
err:
return res;
}
int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
struct mailmh_folder * src_folder,
uint32_t index)
{
int fd;
char * filename;
int r;
#if 0
r = mailmh_folder_update(dest_folder);
if (r != MAILMH_NO_ERROR)
return r;
r = mailmh_folder_update(src_folder);
if (r != MAILMH_NO_ERROR)
return r;
#endif
/* move on the same filesystem */
r = mailmh_folder_get_message_filename(src_folder, index, &filename);
if (r != MAILMH_NO_ERROR)
return r;
r = mailmh_folder_alloc_msg(dest_folder, filename, &index);
free(filename);
if (r == MAILMH_NO_ERROR)
return MAILMH_NO_ERROR;
/* move on the different filesystems */
r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd);
if (r != MAILMH_NO_ERROR)
return r;
r = mailmh_folder_add_message_file(dest_folder, fd);
if (r != MAILMH_NO_ERROR) {
close(fd);
return r;
}
close(fd);
r = mailmh_folder_remove_message(src_folder, index);
return MAILMH_NO_ERROR;
}
unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder)
{
unsigned int i;
unsigned int count;
count = 0;
for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++)
if (carray_get(folder->fl_msgs_tab, i) != NULL)
count ++;
return count;
}