author | erik <erik> | 2007-01-24 19:46:19 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:46:19 (UTC) |
commit | a017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (side-by-side diff) | |
tree | 008be2b62ee5487dc55b8a7c7f043c94268f8362 /noncore | |
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.
-rw-r--r-- | noncore/apps/opie-reader/Bkmks.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 57 | ||||
-rw-r--r-- | noncore/comm/keypebble/vncauth.c | 6 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.c | 4 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/csv.c | 140 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/currency.c | 1 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/lists.h | 1 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/stocks.c | 189 |
9 files changed, 246 insertions, 157 deletions
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp index 00141a3..45aa045 100644 --- a/noncore/apps/opie-reader/Bkmks.cpp +++ b/noncore/apps/opie-reader/Bkmks.cpp @@ -345,2 +345,3 @@ Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f) b = new Bkmk(nm,anno,pos); + delete [] anno; } diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp index 51fe707..27080e9 100644 --- a/noncore/apps/opie-sheet/Excel.cpp +++ b/noncore/apps/opie-sheet/Excel.cpp @@ -379,3 +379,5 @@ char* ExcelBook::GetDataOfBREC(ExcelBREC* record) { - ConvertCharToArray(record,Read(record->position,record->length),record->length); + char* readData = Read(record->position,record->length); + ConvertCharToArray(record,readData,record->length); + delete [] readData; }; diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index f70f863..9c0c6ce 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp @@ -1770,8 +1770,10 @@ int ZSafe::loadInit(const char* _filename, const char *password) - QFileInfo f (_filename); - load_buffer_length = f.size(); - load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; + QFileInfo f (_filename); + load_buffer_length = f.size(); + load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; - if (fd == NULL) + if (fd == NULL) { + delete krc2; return PWERR_OPEN; + } @@ -1790,4 +1792,6 @@ int ZSafe::loadInit(const char* _filename, const char *password) - if (size < 8) + if (size < 8) { + delete krc2; return PWERR_DATA; + } @@ -1811,2 +1815,3 @@ int ZSafe::loadInit(const char* _filename, const char *password) if (count2 == 0) { + delete krc2; return PWERR_DATA; @@ -1831,2 +1836,3 @@ int ZSafe::loadInit(const char* _filename, const char *password) } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ + delete krc2; size -= buffer[size - 1]; @@ -2101,24 +2107,11 @@ int ZSafe::saveInit(const char *_filename, const char *password) - /* first we should check the permissions of the filename */ -/* - if (QFile::exists(_filename)) { - val = checkFile(_filename); - if (val != PWERR_GOOD) - return val; - } else - { - val = creat (_filename, (S_IRUSR | S_IWUSR)); - if (val == -1) - return PWERR_OPEN; - else - close(val); - } -*/ - QFileInfo f (_filename); - save_buffer_length = f.size(); - save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; + QFileInfo f (_filename); + save_buffer_length = f.size(); + save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; fd = fopen (_filename, "wb"); - if (fd == NULL) + if (fd == NULL) { + delete krc2; return PWERR_OPEN; + } @@ -2132,2 +2125,3 @@ int ZSafe::saveInit(const char *_filename, const char *password) krc2->rc2_expandkey (key, keylength, 128); + delete krc2; @@ -2190,4 +2184,10 @@ int ZSafe::saveEntry(char *entry[FIELD_SIZE]) bufferIndex = 0; - if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; - if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; + if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) { + delete krc2; + return PWERR_DATA; + } + if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) { + delete krc2; + return PWERR_DATA; + } } /*for (count3 = 0; count3 < 5; count3++)*/ @@ -2197,4 +2197,4 @@ int ZSafe::saveEntry(char *entry[FIELD_SIZE]) } /*while (count2 < strlen (buffer))*/ - int ret = PWERR_GOOD; - return ret; + delete krc2; + return PWERR_GOOD; } @@ -2230,2 +2230,3 @@ int ZSafe::saveFinalize(void) free(buffer); + delete krc2; return retval; diff --git a/noncore/comm/keypebble/vncauth.c b/noncore/comm/keypebble/vncauth.c index 277d145..7de837a 100644 --- a/noncore/comm/keypebble/vncauth.c +++ b/noncore/comm/keypebble/vncauth.c @@ -96,3 +96,6 @@ vncDecryptPasswdFromFile(char *fname) - if ((fp = fopen(fname,"r")) == NULL) return NULL; + if ((fp = fopen(fname,"r")) == NULL) { + free(passwd); + return NULL; + } @@ -102,2 +105,3 @@ vncDecryptPasswdFromFile(char *fname) fclose(fp); + free(passwd); return NULL; diff --git a/noncore/net/ftplib/ftplib.c b/noncore/net/ftplib/ftplib.c index efcd6f0..addf9d2 100644 --- a/noncore/net/ftplib/ftplib.c +++ b/noncore/net/ftplib/ftplib.c @@ -1174,3 +1174,7 @@ static int FtpXfer(const char *localfile, const char *path, if (!FtpAccess(path, typ, mode, nControl, &nData)) + { + if (localfile != NULL) + fclose(local); return 0; + } dbuf = malloc(FTPLIB_BUFSIZ); diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c index 86d8607..110df7c 100644 --- a/noncore/todayplugins/stockticker/libstocks/csv.c +++ b/noncore/todayplugins/stockticker/libstocks/csv.c @@ -143,3 +143,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(line, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } @@ -156,3 +160,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } @@ -169,3 +177,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->CurrentPrice)); @@ -173,3 +185,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } @@ -186,3 +202,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } @@ -199,3 +219,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->Variation)); @@ -208,3 +232,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->OpenPrice)); @@ -212,3 +240,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->MaxPrice)); @@ -216,3 +248,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->MinPrice)); @@ -220,3 +256,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } StockPtr->Volume = atoi(ptr); @@ -249,3 +289,7 @@ stock *parse_csv_file(char *csv) ptr = csv_strtok(line, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + return 0; + } @@ -330,3 +374,9 @@ stock *parse_csv_history_file(char *csv_file) ptr = strtok(line, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + free_stock(FirstStockPtr); + free_stock(LastStockPtr); + return 0; + } @@ -346,7 +396,7 @@ stock *parse_csv_history_file(char *csv_file) if (date==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } + { + fprintf(stderr,"Memory allocating error (%s line %d)\n" + ,__FILE__, __LINE__); + exit(1); + } sprintf(date,"%.2d%.2d%.2d", year, month, day); @@ -356,3 +406,9 @@ stock *parse_csv_history_file(char *csv_file) ptr = strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + free_stock(FirstStockPtr); + free_stock(LastStockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->OpenPrice)); @@ -361,3 +417,9 @@ stock *parse_csv_history_file(char *csv_file) ptr = strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + free_stock(FirstStockPtr); + free_stock(LastStockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->MaxPrice)); @@ -366,3 +428,9 @@ stock *parse_csv_history_file(char *csv_file) ptr = strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + free_stock(FirstStockPtr); + free_stock(LastStockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->MinPrice)); @@ -371,3 +439,9 @@ stock *parse_csv_history_file(char *csv_file) ptr = strtok(NULL, ","); - if (!ptr) return 0; + if (!ptr) + { + free_stock(StockPtr); + free_stock(FirstStockPtr); + free_stock(LastStockPtr); + return 0; + } sscanf(ptr,"%f",&(StockPtr->LastPrice)); @@ -378,13 +452,13 @@ stock *parse_csv_history_file(char *csv_file) if (!ptr) - /* It seems to be an indice */ - /* No volume for indices */ - StockPtr->Volume = 0; + /* It seems to be an indice */ + /* No volume for indices */ + StockPtr->Volume = 0; else - StockPtr->Volume = atoi(ptr); + StockPtr->Volume = atoi(ptr); if( !FirstStockPtr ) - { - FirstStockPtr = StockPtr; - StockPtr->PreviousStock = 0; - } + { + FirstStockPtr = StockPtr; + StockPtr->PreviousStock = 0; + } @@ -393,6 +467,6 @@ stock *parse_csv_history_file(char *csv_file) if (LastStockPtr) - { - LastStockPtr->NextStock = StockPtr; - StockPtr->PreviousStock = LastStockPtr; - } + { + LastStockPtr->NextStock = StockPtr; + StockPtr->PreviousStock = LastStockPtr; + } diff --git a/noncore/todayplugins/stockticker/libstocks/currency.c b/noncore/todayplugins/stockticker/libstocks/currency.c index 9a08a9d..e0090e2 100644 --- a/noncore/todayplugins/stockticker/libstocks/currency.c +++ b/noncore/todayplugins/stockticker/libstocks/currency.c @@ -54,2 +54,3 @@ libstocks_return_code get_currency_exchange(char *from, error = get_stocks(symbol, &data); + free(symbol); if (error) diff --git a/noncore/todayplugins/stockticker/libstocks/lists.h b/noncore/todayplugins/stockticker/libstocks/lists.h index 0132317..a0eb434 100644 --- a/noncore/todayplugins/stockticker/libstocks/lists.h +++ b/noncore/todayplugins/stockticker/libstocks/lists.h @@ -32,2 +32,3 @@ PUBEXT_LISTS stock *malloc_stock(void); +PUBEXT_LISTS void free_stock(stock*); 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 @@ -107,3 +107,3 @@ yahoo_source find_yahoo_source(char *symbol) } - + /* We suppose now it is a European stock */ @@ -118,4 +118,4 @@ yahoo_source find_yahoo_source(char *symbol) /*****************************************************************************/ -libstocks_return_code download_stocks(char *stocks, - stock **stock_datas, +libstocks_return_code download_stocks(char *stocks, + stock **stock_datas, yahoo_source source) @@ -140,3 +140,3 @@ libstocks_return_code download_stocks(char *stocks, break; - + case YAHOO_EUROPE: @@ -147,3 +147,3 @@ libstocks_return_code download_stocks(char *stocks, break; - + } @@ -166,5 +166,5 @@ libstocks_return_code download_stocks(char *stocks, strcat(url, url_end); - + error=http_get(url, stocks_server, &data); - + free(url); @@ -172,3 +172,3 @@ libstocks_return_code download_stocks(char *stocks, if (error) return error; - + *stock_datas = parse_csv_file(data); @@ -224,3 +224,3 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) ,__FILE__, __LINE__); - exit(1); + exit(1); } @@ -237,73 +237,71 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) switch (source) - { - case YAHOO_US: - - if (us_quotes) - { - lgr_us_quotes = strlen(us_quotes); - lgr_symbol = strlen(symbol); - - us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); - if(us_quotes_temp==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } - strcpy(us_quotes_temp, us_quotes); - strcat(us_quotes_temp,"+"); - strcat(us_quotes_temp,symbol); - - free(us_quotes); - us_quotes = us_quotes_temp; - } - else - { - us_quotes = malloc(strlen(symbol)+1); - - if(us_quotes==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } - strcpy(us_quotes, symbol); - } - - break; - - case YAHOO_EUROPE: - - if (eu_quotes) - { - lgr_eu_quotes = strlen(eu_quotes); - lgr_symbol = strlen(symbol); - - eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); - if(eu_quotes_temp==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } - strcpy(eu_quotes_temp, eu_quotes); - strcat(eu_quotes_temp, "+"); - strcat(eu_quotes_temp, symbol); - - free(eu_quotes); - eu_quotes = eu_quotes_temp; - } - else - { - eu_quotes = malloc(strlen(symbol)+1); - if(eu_quotes==NULL) - { - fprintf(stderr,"Memory allocating error (%s line %d)\n" - ,__FILE__, __LINE__); - exit(1); - } - strcpy(eu_quotes, symbol); - } - break; - } + { + case YAHOO_US: + if (us_quotes) + { + lgr_us_quotes = strlen(us_quotes); + lgr_symbol = strlen(symbol); + + us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); + if(us_quotes_temp==NULL) + { + fprintf(stderr,"Memory allocating error (%s line %d)\n", + __FILE__, __LINE__); + exit(1); + } + strcpy(us_quotes_temp, us_quotes); + strcat(us_quotes_temp,"+"); + strcat(us_quotes_temp,symbol); + + free(us_quotes); + us_quotes = us_quotes_temp; + } + else + { + us_quotes = malloc(strlen(symbol)+1); + + if(us_quotes==NULL) + { + fprintf(stderr,"Memory allocating error (%s line %d)\n", + __FILE__, __LINE__); + exit(1); + } + strcpy(us_quotes, symbol); + } + + break; + + case YAHOO_EUROPE: + if (eu_quotes) + { + lgr_eu_quotes = strlen(eu_quotes); + lgr_symbol = strlen(symbol); + + eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); + if(eu_quotes_temp==NULL) + { + fprintf(stderr,"Memory allocating error (%s line %d)\n", + __FILE__, __LINE__); + exit(1); + } + strcpy(eu_quotes_temp, eu_quotes); + strcat(eu_quotes_temp, "+"); + strcat(eu_quotes_temp, symbol); + + free(eu_quotes); + eu_quotes = eu_quotes_temp; + } + else + { + eu_quotes = malloc(strlen(symbol)+1); + if(eu_quotes==NULL) + { + fprintf(stderr,"Memory allocating error (%s line %d)\n", + __FILE__, __LINE__); + exit(1); + } + strcpy(eu_quotes, symbol); + } + break; + } } @@ -316,5 +314,6 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US); + free(us_quotes); if (error) return error; } - + if (eu_quotes) @@ -323,2 +322,3 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE); + free(eu_quotes); if (error) return error; @@ -327,20 +327,21 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas) if (stocks_tmp) - { - stocks_tmp2 = stocks_tmp; + { + stocks_tmp2 = stocks_tmp; - while(stocks_tmp2 != NULL) - { - last_stock = stocks_tmp2; - stocks_tmp2 = next_stock(stocks_tmp2); - } + while(stocks_tmp2 != NULL) + { + last_stock = stocks_tmp2; + stocks_tmp2 = next_stock(stocks_tmp2); + } - last_stock->NextStock = stocks_getted; - stocks_getted->PreviousStock = last_stock; + last_stock->NextStock = stocks_getted; + stocks_getted->PreviousStock = last_stock; - } - else (stocks_tmp = stocks_getted); + } + else + (stocks_tmp = stocks_getted); } - *stock_datas = stocks_tmp; - + *stock_datas = stocks_tmp; + return(0); |