Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/hbuf.c @ 390:468c9cac2798
Minor changes to hbuf.c
- remove useless do {} while with g_new()
- some g_free() were missing
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 01 Aug 2005 21:43:01 +0100 |
parents | dd9e2eb52916 |
children | 6329c9601704 |
comparison
equal
deleted
inserted
replaced
389:6e895f397474 | 390:468c9cac2798 |
---|---|
60 | 60 |
61 hbuf_block_elt = g_new0(hbuf_block, 1); | 61 hbuf_block_elt = g_new0(hbuf_block, 1); |
62 hbuf_block_elt->prefix.timestamp = timestamp; | 62 hbuf_block_elt->prefix.timestamp = timestamp; |
63 hbuf_block_elt->prefix.flags = prefix_flags; | 63 hbuf_block_elt->prefix.flags = prefix_flags; |
64 if (!hbuf) { | 64 if (!hbuf) { |
65 do { | 65 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); |
66 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); | |
67 } while (!hbuf_block_elt->ptr); | |
68 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; | 66 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
69 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; | 67 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; |
70 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); | 68 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
71 } else { | 69 } else { |
72 hbuf_block *hbuf_b_prev = g_list_last(hbuf)->data; | 70 hbuf_block *hbuf_b_prev = g_list_last(hbuf)->data; |
81 text = "[ERR:LINE_TOO_LONG]"; | 79 text = "[ERR:LINE_TOO_LONG]"; |
82 hbuf_block_elt->prefix.flags |= HBB_PREFIX_INFO; | 80 hbuf_block_elt->prefix.flags |= HBB_PREFIX_INFO; |
83 } | 81 } |
84 if (hbuf_block_elt->ptr + strlen(text) >= hbuf_block_elt->ptr_end_alloc) { | 82 if (hbuf_block_elt->ptr + strlen(text) >= hbuf_block_elt->ptr_end_alloc) { |
85 // Too long for the current allocated bloc, we need another one | 83 // Too long for the current allocated bloc, we need another one |
86 do { | 84 hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); |
87 hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); | |
88 } while (!hbuf_block_elt->ptr); | |
89 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; | 85 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
90 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; | 86 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; |
91 } | 87 } |
92 | 88 |
93 line = hbuf_block_elt->ptr; | 89 line = hbuf_block_elt->ptr; |
149 for (hbuf_elt = first_elt; hbuf_elt; hbuf_elt = g_list_next(hbuf_elt)) { | 145 for (hbuf_elt = first_elt; hbuf_elt; hbuf_elt = g_list_next(hbuf_elt)) { |
150 hbuf_b_elt = (hbuf_block*)(hbuf_elt->data); | 146 hbuf_b_elt = (hbuf_block*)(hbuf_elt->data); |
151 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) { | 147 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) { |
152 g_free(hbuf_b_elt->ptr); | 148 g_free(hbuf_b_elt->ptr); |
153 } | 149 } |
150 g_free(hbuf_b_elt); | |
154 } | 151 } |
155 | 152 |
156 g_list_free(*p_hbuf); | 153 g_list_free(*p_hbuf); |
157 *p_hbuf = NULL; | 154 *p_hbuf = NULL; |
158 } | 155 } |
178 hbuf_b_curr = (hbuf_block*)(curr_elt->data); | 175 hbuf_b_curr = (hbuf_block*)(curr_elt->data); |
179 hbuf_b_next = (hbuf_block*)(next_elt->data); | 176 hbuf_b_next = (hbuf_block*)(next_elt->data); |
180 // Is next line not-persistent? | 177 // Is next line not-persistent? |
181 if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) { | 178 if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) { |
182 hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end; | 179 hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end; |
180 g_free(hbuf_b_next); | |
183 g_list_delete_link(curr_elt, next_elt); | 181 g_list_delete_link(curr_elt, next_elt); |
184 } else | 182 } else |
185 curr_elt = next_elt; | 183 curr_elt = next_elt; |
186 } | 184 } |
187 // #2 Go back to head and create non-persistent blocks when needed | 185 // #2 Go back to head and create non-persistent blocks when needed |