author | zautrix <zautrix> | 2005-01-24 21:00:03 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-24 21:00:03 (UTC) |
commit | 60733d98dff3ff5f8e95c514af258498aa7aa014 (patch) (unidiff) | |
tree | 751d6533a51790da2afa49c870ff2342d6e3b0bf /kmicromail | |
parent | bb33b559609356149ae51cb50c081b3e82aecafb (diff) | |
download | kdepimpi-60733d98dff3ff5f8e95c514af258498aa7aa014.zip kdepimpi-60733d98dff3ff5f8e95c514af258498aa7aa014.tar.gz kdepimpi-60733d98dff3ff5f8e95c514af258498aa7aa014.tar.bz2 |
memory leak fix
-rw-r--r-- | kmicromail/libetpan/mh/mailmh.c | 3 |
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 | |||
@@ -732,259 +732,262 @@ int mailmh_folder_get_message_size(struct mailmh_folder * folder, | |||
732 | return MAILMH_NO_ERROR; | 732 | return MAILMH_NO_ERROR; |
733 | } | 733 | } |
734 | 734 | ||
735 | int mailmh_folder_add_message_uid(struct mailmh_folder * folder, | 735 | int mailmh_folder_add_message_uid(struct mailmh_folder * folder, |
736 | const char * message, size_t size, | 736 | const char * message, size_t size, |
737 | uint32_t * pindex) | 737 | uint32_t * pindex) |
738 | { | 738 | { |
739 | char * tmpname; | 739 | char * tmpname; |
740 | int fd; | 740 | int fd; |
741 | size_t namesize; | 741 | size_t namesize; |
742 | size_t left; | 742 | size_t left; |
743 | ssize_t res; | 743 | ssize_t res; |
744 | struct mailmh_msg_info * msg_info; | 744 | struct mailmh_msg_info * msg_info; |
745 | uint32_t index; | 745 | uint32_t index; |
746 | int error; | 746 | int error; |
747 | int r; | 747 | int r; |
748 | unsigned int array_index; | 748 | unsigned int array_index; |
749 | struct stat buf; | 749 | struct stat buf; |
750 | chashdatum key; | 750 | chashdatum key; |
751 | chashdatum data; | 751 | chashdatum data; |
752 | 752 | ||
753 | #if 0 | 753 | #if 0 |
754 | r = mailmh_folder_update(folder); | 754 | r = mailmh_folder_update(folder); |
755 | if (r != MAILMH_NO_ERROR) { | 755 | if (r != MAILMH_NO_ERROR) { |
756 | error = r; | 756 | error = r; |
757 | goto err; | 757 | goto err; |
758 | } | 758 | } |
759 | #endif | 759 | #endif |
760 | 760 | ||
761 | namesize = strlen(folder->fl_filename) + 20; | 761 | namesize = strlen(folder->fl_filename) + 20; |
762 | tmpname = malloc(namesize); | 762 | tmpname = malloc(namesize); |
763 | snprintf(tmpname, namesize, "%s%ctmpXXXXXX", | 763 | snprintf(tmpname, namesize, "%s%ctmpXXXXXX", |
764 | folder->fl_filename, MAIL_DIR_SEPARATOR); | 764 | folder->fl_filename, MAIL_DIR_SEPARATOR); |
765 | fd = mkstemp(tmpname); | 765 | fd = mkstemp(tmpname); |
766 | if (fd < 0) { | 766 | if (fd < 0) { |
767 | error = MAILMH_ERROR_FILE; | 767 | error = MAILMH_ERROR_FILE; |
768 | goto free; | 768 | goto free; |
769 | } | 769 | } |
770 | 770 | ||
771 | left = size; | 771 | left = size; |
772 | while (left > 0) { | 772 | while (left > 0) { |
773 | res = write(fd, message, left); | 773 | res = write(fd, message, left); |
774 | if (res == -1) { | 774 | if (res == -1) { |
775 | close(fd); | 775 | close(fd); |
776 | error = MAILMH_ERROR_FILE; | 776 | error = MAILMH_ERROR_FILE; |
777 | goto free; | 777 | goto free; |
778 | } | 778 | } |
779 | 779 | ||
780 | left -= res; | 780 | left -= res; |
781 | } | 781 | } |
782 | close(fd); | 782 | close(fd); |
783 | 783 | ||
784 | r = stat(tmpname, &buf); | 784 | r = stat(tmpname, &buf); |
785 | if (r < 0) { | 785 | if (r < 0) { |
786 | error = MAILMH_ERROR_FILE; | 786 | error = MAILMH_ERROR_FILE; |
787 | goto free; | 787 | goto free; |
788 | } | 788 | } |
789 | 789 | ||
790 | r = mailmh_folder_alloc_msg(folder, tmpname, &index); | 790 | r = mailmh_folder_alloc_msg(folder, tmpname, &index); |
791 | if (r != MAILMH_NO_ERROR) { | 791 | if (r != MAILMH_NO_ERROR) { |
792 | unlink(tmpname); | 792 | unlink(tmpname); |
793 | error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG; | 793 | error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG; |
794 | goto free; | 794 | goto free; |
795 | } | 795 | } |
796 | free(tmpname); | 796 | free(tmpname); |
797 | 797 | ||
798 | msg_info = mailmh_msg_info_new(index, size, buf.st_mtime); | 798 | msg_info = mailmh_msg_info_new(index, size, buf.st_mtime); |
799 | if (msg_info == NULL) { | 799 | if (msg_info == NULL) { |
800 | mailmh_folder_remove_message(folder, index); | 800 | mailmh_folder_remove_message(folder, index); |
801 | error = MAILMH_ERROR_MEMORY; | 801 | error = MAILMH_ERROR_MEMORY; |
802 | goto err; | 802 | goto err; |
803 | } | 803 | } |
804 | 804 | ||
805 | r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); | 805 | r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); |
806 | if (r < 0) { | 806 | if (r < 0) { |
807 | mailmh_folder_remove_message(folder, index); | 807 | mailmh_folder_remove_message(folder, index); |
808 | mailmh_msg_info_free(msg_info); | 808 | mailmh_msg_info_free(msg_info); |
809 | error = MAILMH_ERROR_MEMORY; | 809 | error = MAILMH_ERROR_MEMORY; |
810 | goto err; | 810 | goto err; |
811 | } | 811 | } |
812 | msg_info->msg_array_index = array_index; | 812 | msg_info->msg_array_index = array_index; |
813 | 813 | ||
814 | #if 0 | 814 | #if 0 |
815 | r = cinthash_add(folder->fl_msgs_hash, index, msg_info); | 815 | r = cinthash_add(folder->fl_msgs_hash, index, msg_info); |
816 | #endif | 816 | #endif |
817 | key.data = &index; | 817 | key.data = &index; |
818 | key.len = sizeof(index); | 818 | key.len = sizeof(index); |
819 | data.data = msg_info; | 819 | data.data = msg_info; |
820 | data.len = 0; | 820 | data.len = 0; |
821 | 821 | ||
822 | if (pindex != NULL) | 822 | if (pindex != NULL) |
823 | * pindex = index; | 823 | * pindex = index; |
824 | 824 | ||
825 | r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); | 825 | r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); |
826 | if (r < 0) { | 826 | if (r < 0) { |
827 | carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); | 827 | carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); |
828 | mailmh_msg_info_free(msg_info); | 828 | mailmh_msg_info_free(msg_info); |
829 | error = MAILMH_ERROR_MEMORY; | 829 | error = MAILMH_ERROR_MEMORY; |
830 | goto err; | 830 | goto err; |
831 | } | 831 | } |
832 | 832 | ||
833 | return MAILMH_NO_ERROR; | 833 | return MAILMH_NO_ERROR; |
834 | 834 | ||
835 | free: | 835 | free: |
836 | free(tmpname); | 836 | free(tmpname); |
837 | err: | 837 | err: |
838 | return error; | 838 | return error; |
839 | } | 839 | } |
840 | 840 | ||
841 | int mailmh_folder_add_message(struct mailmh_folder * folder, | 841 | int mailmh_folder_add_message(struct mailmh_folder * folder, |
842 | const char * message, size_t size) | 842 | const char * message, size_t size) |
843 | { | 843 | { |
844 | return mailmh_folder_add_message_uid(folder, message, size, NULL); | 844 | return mailmh_folder_add_message_uid(folder, message, size, NULL); |
845 | } | 845 | } |
846 | 846 | ||
847 | int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder, | 847 | int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder, |
848 | int fd, uint32_t * pindex) | 848 | int fd, uint32_t * pindex) |
849 | { | 849 | { |
850 | char * message; | 850 | char * message; |
851 | struct stat buf; | 851 | struct stat buf; |
852 | int r; | 852 | int r; |
853 | 853 | ||
854 | #if 0 | 854 | #if 0 |
855 | r = mailmh_folder_update(folder); | 855 | r = mailmh_folder_update(folder); |
856 | if (r != MAILMH_NO_ERROR) | 856 | if (r != MAILMH_NO_ERROR) |
857 | return r; | 857 | return r; |
858 | #endif | 858 | #endif |
859 | 859 | ||
860 | if (fstat(fd, &buf) == -1) | 860 | if (fstat(fd, &buf) == -1) |
861 | return MAILMH_ERROR_FILE; | 861 | return MAILMH_ERROR_FILE; |
862 | 862 | ||
863 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | 863 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
864 | if (message == MAP_FAILED) | 864 | if (message == MAP_FAILED) |
865 | return MAILMH_ERROR_FILE; | 865 | return MAILMH_ERROR_FILE; |
866 | 866 | ||
867 | r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex); | 867 | r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex); |
868 | 868 | ||
869 | munmap(message, buf.st_size); | 869 | munmap(message, buf.st_size); |
870 | 870 | ||
871 | return r; | 871 | return r; |
872 | } | 872 | } |
873 | 873 | ||
874 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, | 874 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, |
875 | int fd) | 875 | int fd) |
876 | { | 876 | { |
877 | return mailmh_folder_add_message_file_uid(folder, fd, NULL); | 877 | return mailmh_folder_add_message_file_uid(folder, fd, NULL); |
878 | } | 878 | } |
879 | 879 | ||
880 | int mailmh_folder_remove_message(struct mailmh_folder * folder, | 880 | int mailmh_folder_remove_message(struct mailmh_folder * folder, |
881 | uint32_t index) | 881 | uint32_t index) |
882 | { | 882 | { |
883 | char * filename; | 883 | char * filename; |
884 | struct mailmh_msg_info * msg_info; | 884 | struct mailmh_msg_info * msg_info; |
885 | int res; | 885 | int res; |
886 | int r; | 886 | int r; |
887 | chashdatum key; | 887 | chashdatum key; |
888 | chashdatum data; | 888 | chashdatum data; |
889 | 889 | ||
890 | #if 0 | 890 | #if 0 |
891 | r = mailmh_folder_update(folder); | 891 | r = mailmh_folder_update(folder); |
892 | if (r != MAILMH_NO_ERROR) { | 892 | if (r != MAILMH_NO_ERROR) { |
893 | res = r; | 893 | res = r; |
894 | goto err; | 894 | goto err; |
895 | } | 895 | } |
896 | #endif | 896 | #endif |
897 | 897 | ||
898 | r = mailmh_folder_get_message_filename(folder, index, &filename); | 898 | r = mailmh_folder_get_message_filename(folder, index, &filename); |
899 | if (filename == NULL) { | 899 | if (filename == NULL) { |
900 | res = r; | 900 | res = r; |
901 | goto err; | 901 | goto err; |
902 | } | 902 | } |
903 | 903 | ||
904 | if (unlink(filename) == -1) { | 904 | if (unlink(filename) == -1) { |
905 | res = MAILMH_ERROR_FILE; | 905 | res = MAILMH_ERROR_FILE; |
906 | goto free; | 906 | goto free; |
907 | } | 907 | } |
908 | 908 | ||
909 | key.data = &index; | 909 | key.data = &index; |
910 | key.len = sizeof(index); | 910 | key.len = sizeof(index); |
911 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 911 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
912 | #if 0 | 912 | #if 0 |
913 | msg_info = cinthash_find(folder->fl_msgs_hash, index); | 913 | msg_info = cinthash_find(folder->fl_msgs_hash, index); |
914 | #endif | 914 | #endif |
915 | if (r == 0) { | 915 | if (r == 0) { |
916 | msg_info = data.data; | 916 | msg_info = data.data; |
917 | 917 | ||
918 | carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); | 918 | carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); |
919 | #if 0 | 919 | #if 0 |
920 | cinthash_remove(folder->fl_msgs_hash, index); | 920 | cinthash_remove(folder->fl_msgs_hash, index); |
921 | #endif | 921 | #endif |
922 | chash_delete(folder->fl_msgs_hash, &key, NULL); | 922 | chash_delete(folder->fl_msgs_hash, &key, NULL); |
923 | } | 923 | } |
924 | // LR | ||
925 | mailmh_msg_info_free( msg_info ); | ||
926 | free(filename); | ||
924 | 927 | ||
925 | return MAILMH_NO_ERROR; | 928 | return MAILMH_NO_ERROR; |
926 | 929 | ||
927 | free: | 930 | free: |
928 | free(filename); | 931 | free(filename); |
929 | err: | 932 | err: |
930 | return res; | 933 | return res; |
931 | } | 934 | } |
932 | 935 | ||
933 | 936 | ||
934 | int mailmh_folder_move_message(struct mailmh_folder * dest_folder, | 937 | int mailmh_folder_move_message(struct mailmh_folder * dest_folder, |
935 | struct mailmh_folder * src_folder, | 938 | struct mailmh_folder * src_folder, |
936 | uint32_t index) | 939 | uint32_t index) |
937 | { | 940 | { |
938 | int fd; | 941 | int fd; |
939 | char * filename; | 942 | char * filename; |
940 | int r; | 943 | int r; |
941 | 944 | ||
942 | #if 0 | 945 | #if 0 |
943 | r = mailmh_folder_update(dest_folder); | 946 | r = mailmh_folder_update(dest_folder); |
944 | if (r != MAILMH_NO_ERROR) | 947 | if (r != MAILMH_NO_ERROR) |
945 | return r; | 948 | return r; |
946 | r = mailmh_folder_update(src_folder); | 949 | r = mailmh_folder_update(src_folder); |
947 | if (r != MAILMH_NO_ERROR) | 950 | if (r != MAILMH_NO_ERROR) |
948 | return r; | 951 | return r; |
949 | #endif | 952 | #endif |
950 | 953 | ||
951 | /* move on the same filesystem */ | 954 | /* move on the same filesystem */ |
952 | r = mailmh_folder_get_message_filename(src_folder, index, &filename); | 955 | r = mailmh_folder_get_message_filename(src_folder, index, &filename); |
953 | if (r != MAILMH_NO_ERROR) | 956 | if (r != MAILMH_NO_ERROR) |
954 | return r; | 957 | return r; |
955 | 958 | ||
956 | r = mailmh_folder_alloc_msg(dest_folder, filename, &index); | 959 | r = mailmh_folder_alloc_msg(dest_folder, filename, &index); |
957 | free(filename); | 960 | free(filename); |
958 | if (r == MAILMH_NO_ERROR) | 961 | if (r == MAILMH_NO_ERROR) |
959 | return MAILMH_NO_ERROR; | 962 | return MAILMH_NO_ERROR; |
960 | 963 | ||
961 | /* move on the different filesystems */ | 964 | /* move on the different filesystems */ |
962 | r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd); | 965 | r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd); |
963 | if (r != MAILMH_NO_ERROR) | 966 | if (r != MAILMH_NO_ERROR) |
964 | return r; | 967 | return r; |
965 | 968 | ||
966 | r = mailmh_folder_add_message_file(dest_folder, fd); | 969 | r = mailmh_folder_add_message_file(dest_folder, fd); |
967 | if (r != MAILMH_NO_ERROR) { | 970 | if (r != MAILMH_NO_ERROR) { |
968 | close(fd); | 971 | close(fd); |
969 | return r; | 972 | return r; |
970 | } | 973 | } |
971 | 974 | ||
972 | close(fd); | 975 | close(fd); |
973 | 976 | ||
974 | r = mailmh_folder_remove_message(src_folder, index); | 977 | r = mailmh_folder_remove_message(src_folder, index); |
975 | 978 | ||
976 | return MAILMH_NO_ERROR; | 979 | return MAILMH_NO_ERROR; |
977 | } | 980 | } |
978 | 981 | ||
979 | unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder) | 982 | unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder) |
980 | { | 983 | { |
981 | unsigned int i; | 984 | unsigned int i; |
982 | unsigned int count; | 985 | unsigned int count; |
983 | 986 | ||
984 | count = 0; | 987 | count = 0; |
985 | for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) | 988 | for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) |
986 | if (carray_get(folder->fl_msgs_tab, i) != NULL) | 989 | if (carray_get(folder->fl_msgs_tab, i) != NULL) |
987 | count ++; | 990 | count ++; |
988 | 991 | ||
989 | return count; | 992 | return count; |
990 | } | 993 | } |