From: Melvin H. <mha...@us...> - 2003-06-29 21:55:41
|
Update of /cvsroot/libetpan/xetpan/src In directory sc8-pr-cvs1:/tmp/cvs-serv8444/src Modified Files: utils.c Log Message: * src/utils.c: - a_Utils_inlined_list_free(): fixed memleak - a_Utils_inlined_data_free(): handle correctly all inlined data types - a_Utils_memmem(): fix invalid memory access: first test for valid index before access to memory - a_Utils_parse_body_text(): optimiztion: do not scan again for inlined data types if they were already found at the previous iteration but were not processed. Index: utils.c =================================================================== RCS file: /cvsroot/libetpan/xetpan/src/utils.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- utils.c 29 Jun 2003 15:54:28 -0000 1.16 +++ utils.c 29 Jun 2003 21:55:31 -0000 1.17 @@ -636,6 +636,7 @@ a_Utils_inlined_list_free(clist *inlined_list) { clist_foreach(inlined_list, (clist_func) a_Utils_inlined_data_free, NULL); + clist_free(inlined_list); } void @@ -646,13 +647,22 @@ x_free(inlined_data->any.data); - if (inlined_data->any.type == XEP_INLINED_DATA_TEXT) + switch (inlined_data->any.type) { + case XEP_INLINED_DATA_TEXT: + case XEP_INLINED_DATA_CLEARSIGNED_TEXT: + case XEP_INLINED_DATA_ASCII_ARMORED_TEXT: x_free(inlined_data->text.plain_text); - } - else - { + break; + case XEP_INLINED_DATA_UUENCODED: + case XEP_INLINED_DATA_YENCODED: + case XEP_INLINED_DATA_YENCODED2: + case XEP_INLINED_DATA_BINHEX: x_free(inlined_data->file.filename); + break; + default: + A_LOGGING_SYSTEM_ERROR("Internal error: attempt to free unknown inlined " + "data"); } x_free(inlined_data); } @@ -1244,7 +1254,7 @@ if (rem_len < needle_len) return NULL; i = 1; - for (i = 1; hs_p[i] == n_p[i] && i < needle_len; i++) + for (i = 1; (i < needle_len) && (hs_p[i] == n_p[i]); i++) { /* Empty on purpose: the search is done in the for loop */ } @@ -2000,6 +2010,7 @@ }; XePUtilsInlinedData *inlined_data[SCAN_FUNC_NB]; XePUtilsInlinedData *first_data = NULL; + XePUtilsInlinedData *prev_data = NULL; XePUtilsInlinedData *text_data = NULL; int i_found[SCAN_FUNC_NB]; int i; @@ -2015,6 +2026,7 @@ for (i = 0; i < SCAN_FUNC_NB; i++) { i_found[i] = 1; + inlined_data[i] = NULL; } remaining_len = size; @@ -2025,13 +2037,25 @@ /* Check for uuencoded, yEnc or yEnc2 or BinHex 4.0 data. * Check again only if something was found the last time we checked. */ + prev_data = first_data; first_data = NULL; for (i = 0; i < SCAN_FUNC_NB; i++) { if (i_found[i]) { - scan_func[i](data_p, remaining_len); - (inlined_data[i]) = (scan_func[i])(data_p, remaining_len); + /* We do not need to scan again for a certain type of inlined + * data if this very type was found in the previous iteration + * and if it was not processed because another type was found before it. + * Thus, we scan only when it is the first ever scan of this type + * or when we already processed this very inlined_data at + * the previous iteration. + */ + if ((inlined_data[i] == NULL) || + (prev_data && inlined_data[i]->any.start == prev_data->any.start)) + { + inlined_data[i] = scan_func[i](data_p, remaining_len); + } + if (inlined_data[i]) { if ((!first_data) || |