author | erik <erik> | 2007-01-24 19:46:19 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:46:19 (UTC) |
commit | a017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (unidiff) | |
tree | 008be2b62ee5487dc55b8a7c7f043c94268f8362 /noncore/todayplugins/stockticker/libstocks/stocks.c | |
parent | a4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff) | |
download | opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.zip opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.gz opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.bz2 |
Every file in this commit has a memory leak of some kind or another. I think
all of them are minor and should not effect properly running code. But if I
were you I would give libstocks and the stockticker plugin in Today a wide
berth. That library is atrocious.
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/stocks.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/stocks.c | 189 |
1 files changed, 95 insertions, 94 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/stocks.c b/noncore/todayplugins/stockticker/libstocks/stocks.c index eb04ba9..3a26a47 100644 --- a/noncore/todayplugins/stockticker/libstocks/stocks.c +++ b/noncore/todayplugins/stockticker/libstocks/stocks.c | |||
@@ -106,5 +106,5 @@ yahoo_source find_yahoo_source(char *symbol) | |||
106 | if (!test) return YAHOO_US; | 106 | if (!test) return YAHOO_US; |
107 | } | 107 | } |
108 | 108 | ||
109 | /* We suppose now it is a European stock */ | 109 | /* We suppose now it is a European stock */ |
110 | return YAHOO_EUROPE; | 110 | return YAHOO_EUROPE; |
@@ -117,6 +117,6 @@ yahoo_source find_yahoo_source(char *symbol) | |||
117 | /* count allows to connect to all country servers */ | 117 | /* count allows to connect to all country servers */ |
118 | /*****************************************************************************/ | 118 | /*****************************************************************************/ |
119 | libstocks_return_code download_stocks(char *stocks, | 119 | libstocks_return_code download_stocks(char *stocks, |
120 | stock **stock_datas, | 120 | stock **stock_datas, |
121 | yahoo_source source) | 121 | yahoo_source source) |
122 | { | 122 | { |
@@ -139,5 +139,5 @@ libstocks_return_code download_stocks(char *stocks, | |||
139 | stocks_server = (char *)yahoo_us_stocks_server; | 139 | stocks_server = (char *)yahoo_us_stocks_server; |
140 | break; | 140 | break; |
141 | 141 | ||
142 | case YAHOO_EUROPE: | 142 | case YAHOO_EUROPE: |
143 | stocks_server = (char *)yahoo_eu_stocks_server; | 143 | stocks_server = (char *)yahoo_eu_stocks_server; |
@@ -146,5 +146,5 @@ libstocks_return_code download_stocks(char *stocks, | |||
146 | stocks_server = (char *)yahoo_us_stocks_server; | 146 | stocks_server = (char *)yahoo_us_stocks_server; |
147 | break; | 147 | break; |
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
@@ -165,11 +165,11 @@ libstocks_return_code download_stocks(char *stocks, | |||
165 | strcat(url, stocks); | 165 | strcat(url, stocks); |
166 | strcat(url, url_end); | 166 | strcat(url, url_end); |
167 | 167 | ||
168 | error=http_get(url, stocks_server, &data); | 168 | error=http_get(url, stocks_server, &data); |
169 | 169 | ||
170 | free(url); | 170 | free(url); |
171 | 171 | ||
172 | if (error) return error; | 172 | if (error) return error; |
173 | 173 | ||
174 | *stock_datas = parse_csv_file(data); | 174 | *stock_datas = parse_csv_file(data); |
175 | 175 | ||
@@ -223,5 +223,5 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
223 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 223 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
224 | ,__FILE__, __LINE__); | 224 | ,__FILE__, __LINE__); |
225 | exit(1); | 225 | exit(1); |
226 | } | 226 | } |
227 | strcpy(tok_ptr, stocks); | 227 | strcpy(tok_ptr, stocks); |
@@ -236,75 +236,73 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
236 | 236 | ||
237 | switch (source) | 237 | switch (source) |
238 | { | 238 | { |
239 | case YAHOO_US: | 239 | case YAHOO_US: |
240 | 240 | if (us_quotes) | |
241 | if (us_quotes) | 241 | { |
242 | { | 242 | lgr_us_quotes = strlen(us_quotes); |
243 | lgr_us_quotes = strlen(us_quotes); | 243 | lgr_symbol = strlen(symbol); |
244 | lgr_symbol = strlen(symbol); | 244 | |
245 | 245 | us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); | |
246 | us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); | 246 | if(us_quotes_temp==NULL) |
247 | if(us_quotes_temp==NULL) | 247 | { |
248 | { | 248 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
249 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 249 | __FILE__, __LINE__); |
250 | ,__FILE__, __LINE__); | 250 | exit(1); |
251 | exit(1); | 251 | } |
252 | } | 252 | strcpy(us_quotes_temp, us_quotes); |
253 | strcpy(us_quotes_temp, us_quotes); | 253 | strcat(us_quotes_temp,"+"); |
254 | strcat(us_quotes_temp,"+"); | 254 | strcat(us_quotes_temp,symbol); |
255 | strcat(us_quotes_temp,symbol); | 255 | |
256 | 256 | free(us_quotes); | |
257 | free(us_quotes); | 257 | us_quotes = us_quotes_temp; |
258 | us_quotes = us_quotes_temp; | 258 | } |
259 | } | 259 | else |
260 | else | 260 | { |
261 | { | 261 | us_quotes = malloc(strlen(symbol)+1); |
262 | us_quotes = malloc(strlen(symbol)+1); | 262 | |
263 | 263 | if(us_quotes==NULL) | |
264 | if(us_quotes==NULL) | 264 | { |
265 | { | 265 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
266 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 266 | __FILE__, __LINE__); |
267 | ,__FILE__, __LINE__); | 267 | exit(1); |
268 | exit(1); | 268 | } |
269 | } | 269 | strcpy(us_quotes, symbol); |
270 | strcpy(us_quotes, symbol); | 270 | } |
271 | } | 271 | |
272 | 272 | break; | |
273 | break; | 273 | |
274 | 274 | case YAHOO_EUROPE: | |
275 | case YAHOO_EUROPE: | 275 | if (eu_quotes) |
276 | 276 | { | |
277 | if (eu_quotes) | 277 | lgr_eu_quotes = strlen(eu_quotes); |
278 | { | 278 | lgr_symbol = strlen(symbol); |
279 | lgr_eu_quotes = strlen(eu_quotes); | 279 | |
280 | lgr_symbol = strlen(symbol); | 280 | eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); |
281 | 281 | if(eu_quotes_temp==NULL) | |
282 | eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); | 282 | { |
283 | if(eu_quotes_temp==NULL) | 283 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
284 | { | 284 | __FILE__, __LINE__); |
285 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 285 | exit(1); |
286 | ,__FILE__, __LINE__); | 286 | } |
287 | exit(1); | 287 | strcpy(eu_quotes_temp, eu_quotes); |
288 | } | 288 | strcat(eu_quotes_temp, "+"); |
289 | strcpy(eu_quotes_temp, eu_quotes); | 289 | strcat(eu_quotes_temp, symbol); |
290 | strcat(eu_quotes_temp, "+"); | 290 | |
291 | strcat(eu_quotes_temp, symbol); | 291 | free(eu_quotes); |
292 | 292 | eu_quotes = eu_quotes_temp; | |
293 | free(eu_quotes); | 293 | } |
294 | eu_quotes = eu_quotes_temp; | 294 | else |
295 | } | 295 | { |
296 | else | 296 | eu_quotes = malloc(strlen(symbol)+1); |
297 | { | 297 | if(eu_quotes==NULL) |
298 | eu_quotes = malloc(strlen(symbol)+1); | 298 | { |
299 | if(eu_quotes==NULL) | 299 | fprintf(stderr,"Memory allocating error (%s line %d)\n", |
300 | { | 300 | __FILE__, __LINE__); |
301 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 301 | exit(1); |
302 | ,__FILE__, __LINE__); | 302 | } |
303 | exit(1); | 303 | strcpy(eu_quotes, symbol); |
304 | } | 304 | } |
305 | strcpy(eu_quotes, symbol); | 305 | break; |
306 | } | 306 | } |
307 | break; | ||
308 | } | ||
309 | } | 307 | } |
310 | 308 | ||
@@ -315,33 +313,36 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) | |||
315 | /* Gets us quotes */ | 313 | /* Gets us quotes */ |
316 | error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US); | 314 | error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US); |
315 | free(us_quotes); | ||
317 | if (error) return error; | 316 | if (error) return error; |
318 | } | 317 | } |
319 | 318 | ||
320 | if (eu_quotes) | 319 | if (eu_quotes) |
321 | { | 320 | { |
322 | /* Gets european quotes */ | 321 | /* Gets european quotes */ |
323 | error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE); | 322 | error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE); |
323 | free(eu_quotes); | ||
324 | if (error) return error; | 324 | if (error) return error; |
325 | 325 | ||
326 | /* concats lists if needed */ | 326 | /* concats lists if needed */ |
327 | if (stocks_tmp) | 327 | if (stocks_tmp) |
328 | { | 328 | { |
329 | stocks_tmp2 = stocks_tmp; | 329 | stocks_tmp2 = stocks_tmp; |
330 | 330 | ||
331 | while(stocks_tmp2 != NULL) | 331 | while(stocks_tmp2 != NULL) |
332 | { | 332 | { |
333 | last_stock = stocks_tmp2; | 333 | last_stock = stocks_tmp2; |
334 | stocks_tmp2 = next_stock(stocks_tmp2); | 334 | stocks_tmp2 = next_stock(stocks_tmp2); |
335 | } | 335 | } |
336 | 336 | ||
337 | last_stock->NextStock = stocks_getted; | 337 | last_stock->NextStock = stocks_getted; |
338 | stocks_getted->PreviousStock = last_stock; | 338 | stocks_getted->PreviousStock = last_stock; |
339 | 339 | ||
340 | } | 340 | } |
341 | else (stocks_tmp = stocks_getted); | 341 | else |
342 | (stocks_tmp = stocks_getted); | ||
342 | } | 343 | } |
343 | 344 | ||
344 | *stock_datas = stocks_tmp; | 345 | *stock_datas = stocks_tmp; |
345 | 346 | ||
346 | return(0); | 347 | return(0); |
347 | } | 348 | } |