summaryrefslogtreecommitdiff
path: root/noncore/apps
authorerik <erik>2007-01-24 19:46:19 (UTC)
committer erik <erik>2007-01-24 19:46:19 (UTC)
commita017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (side-by-side diff)
tree008be2b62ee5487dc55b8a7c7f043c94268f8362 /noncore/apps
parenta4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff)
downloadopie-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/apps') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp1
-rw-r--r--noncore/apps/opie-sheet/Excel.cpp4
-rw-r--r--noncore/apps/zsafe/zsafe.cpp45
3 files changed, 27 insertions, 23 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
@@ -322,48 +322,49 @@ Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f)
delete [] anno;
}
}
return b;
}
Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
tchar* nm = new tchar[ln+1];
fread(nm,sizeof(tchar),ln,f);
nm[ln] = 0;
fread(&ln,sizeof(ln),1,f);
tchar* anno = new tchar[ln+1];
if (ln > 0) fread(anno,sizeof(tchar),ln,f);
anno[ln] = 0;
unsigned int pos;
fread(&pos,sizeof(pos),1,f);
b = new Bkmk(nm,anno,pos);
+ delete [] anno;
}
}
return b;
}
Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
b = new Bkmk;
b->m_namelen = ln;
b->m_name = new unsigned char[b->m_namelen];
fread(b->m_name,1,b->m_namelen,f);
fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
if (b->m_annolen > 0)
{
b->m_anno = new unsigned char[b->m_annolen];
fread(b->m_anno,1,b->m_annolen,f);
}
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
@@ -356,49 +356,51 @@ ExcelBREC* ExcelBook::GetBREC(void)
rec= new ExcelBREC;
if(FileEOF()) return NULL;
rec->data=NULL;
rec->code=Get2Bytes();
rec->length=Get2Bytes();
rec->position=Position;
SeekSkip(rec->length);
return rec;
};
ExcelBREC* ExcelBook::PeekBREC(void)
{
int oldpos;
ExcelBREC* NextRec;
oldpos=Position;
NextRec=GetBREC();
SeekPosition(oldpos);
return NextRec;
};
char* ExcelBook::GetDataOfBREC(ExcelBREC* record)
{
if(record->data==NULL)
{
- ConvertCharToArray(record,Read(record->position,record->length),record->length);
+ char* readData = Read(record->position,record->length);
+ ConvertCharToArray(record,readData,record->length);
+ delete [] readData;
};
return record->data;//new?
};
void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length)
{
record->data=new char[length];
for(int w1=0;w1<=length-1;w1++)
record->data[w1]=chars[w1];
};
bool ExcelSheet::InitCells()
{
int r;
Cells.resize(rows * cols + cols+1);
if(Cells.count()==0) return false;
for(r=0;r < Cells.count();r++)
{
Cells[r]=NULL;
};
return true;
};
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
@@ -1751,105 +1751,111 @@ bool ZSafe::openDocument(const char* _filename, const char* )
}
}
retval = loadFinalize();
return true;
}
int ZSafe::loadInit(const char* _filename, const char *password)
{
unsigned int j = 0;
unsigned int keylength=0;
int count=0, count2=0, count3=0;
unsigned char charbuf[8];
unsigned short ciphertext[4];
char key[128];
Krc2* krc2 = new Krc2();
fd = fopen (_filename, "rb");
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;
+ }
buffer = (char *)malloc(load_buffer_length);
for (j = 0; password[j] != '\0'; j++) {
key[j] = password[j];
}
keylength = j;
krc2->rc2_expandkey (key, keylength, 128);
#ifndef Q_WS_WIN
size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
#else
size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
#endif
- if (size < 8)
+ if (size < 8) {
+ delete krc2;
return PWERR_DATA;
+ }
for (count = 0; count < 4; count++) {
count2 = count << 1;
iv[count] = charbuf[count2] << 8;
iv[count] += charbuf[count2 + 1];
}
size = 0;
bufferIndex = 0;
#ifndef Q_WS_WIN
while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
while (count < 8) {
count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
#else
while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
while (count < 8) {
count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
#endif
if (count2 == 0) {
+ delete krc2;
return PWERR_DATA;
}
count += count2;
} /* while (count < 8) */
size += 8;
for (count2 = 0; count2 < 8; count2 += 2) {
count3 = count2 >> 1;
ciphertext[count3] = charbuf[count2] << 8;
ciphertext[count3] += charbuf[count2 + 1];
plaintext[count3] = ciphertext[count3] ^ iv[count3];
iv[count3] = plaintext[count3];
} /* for (count2) */
krc2->rc2_decrypt (plaintext);
memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
bufferIndex += 8;
buffer[bufferIndex + 1] = '\0';
} /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
+ delete krc2;
size -= buffer[size - 1];
lastcount = 0;
/* This will point to the starting index */
bufferIndex = 0;
return PWERR_GOOD;
}
int ZSafe::loadEntry(char *entry[FIELD_SIZE])
{
/* Strip off PKCS 5 padding
* Should check to make sure it's good here
*/
int count, count1=0;
for (count = lastcount; count < size; count++) {
if ((unsigned char) (buffer[count]) == 255) {
if (buffer[bufferIndex] == '\0') {
bufferIndex++;
}
entry[count1] = (char *) malloc (count - bufferIndex + 1);
memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
entry[count1][count - bufferIndex] = '\0';
count++;
@@ -2078,79 +2084,67 @@ void ZSafe::getDocPassword(QString title)
dialog->PasswordField->setFocus();
QDialog::DialogCode result = (QDialog::DialogCode) dialog->exec();
QString password;
if (result == QDialog::Accepted || newPwdDialogResult)
{
m_password = dialog->PasswordField->text();
}
else
{
exitZs (1);
}
}
int ZSafe::saveInit(const char *_filename, const char *password)
{
char key[128];
unsigned int j = 0;
unsigned int keylength;
// int val;
int count2;
Krc2* krc2 = new Krc2();
- /* 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;
fd = fopen (_filename, "wb");
- if (fd == NULL)
+ if (fd == NULL) {
+ delete krc2;
return PWERR_OPEN;
+ }
buffer = (char*)malloc(save_buffer_length);
/* make the key ready */
for (j = 0; password[j] != '\0'; j++) {
key[j] = password[j];
}
keylength = j;
krc2->rc2_expandkey (key, keylength, 128);
+ delete krc2;
/* First, we make the IV */
for (count2 = 0; count2 < 4; count2++) {
iv[count2] = rand ();
putc ((unsigned char) (iv[count2] >> 8), fd);
putc ((unsigned char) (iv[count2] & 0xff), fd);
}
bufferIndex = 0;
return PWERR_GOOD;
}
int ZSafe::saveEntry(char *entry[FIELD_SIZE])
{
char *text1;
int count2, count3;
unsigned short ciphertext[4];
Krc2* krc2 = new Krc2();
buffer = (char*)memset(buffer, '\0', save_buffer_length);
for (count2 = 0; count2 < FIELD_SIZE; count2++) {
text1 = entry[count2];
@@ -2167,88 +2161,95 @@ int ZSafe::saveEntry(char *entry[FIELD_SIZE])
* At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
* PKCS 5 padding (explained at the code section
*/
while (count2 < (int)strlen (buffer)) {
#ifndef WORDS_BIGENDIAN
plaintext[bufferIndex] = buffer[count2 + 1] << 8;
plaintext[bufferIndex] += buffer[count2] & 0xff;
#endif
#ifdef WORDS_BIGENDIAN
plaintext[bufferIndex] = buffer[count2] << 8;
plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
#endif
bufferIndex++;
if (bufferIndex == 4) {
krc2->rc2_encrypt (plaintext);
for (count3 = 0; count3 < 4; count3++) {
ciphertext[count3] = iv[count3] ^ plaintext[count3];
/* Now store the ciphertext as the iv */
iv[count3] = plaintext[count3];
/* reset the buffer index */
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++)*/
} /*if (bufferIndex == 5)*/
/* increment a short, not a byte */
count2 += 2;
} /*while (count2 < strlen (buffer))*/
- int ret = PWERR_GOOD;
- return ret;
+ delete krc2;
+ return PWERR_GOOD;
}
int ZSafe::saveFinalize(void)
{
int count1, retval = PWERR_GOOD;
unsigned short ciphertext[4];
Krc2* krc2 = new Krc2();
/* Tack on the PKCS 5 padding
* How it works is we fill up the last n bytes with the value n
*
* So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
* over, leaving us 3 short, so we fill it in with 3's.
*
* If we come out even, we fill it with 8 8s
*
* um, except that in this instance we are using 4 shorts instead of 8 bytes.
* so, half everything
*/
for (count1 = bufferIndex; count1 < 4; count1++) {
plaintext[count1] = (4 - bufferIndex);
}
krc2->rc2_encrypt (plaintext);
for (count1 = 0; count1 < 4; count1++) {
ciphertext[count1] = iv[count1] ^ plaintext[count1];
if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
}
fclose (fd);
free(buffer);
+ delete krc2;
return retval;
}
void ZSafe::quitMe ()
{
if (modified)
{
switch( QMessageBox::information( this, tr("ZSafe"),
tr("Do you want to save\nbefore exiting?"),
tr("&Save"),
tr("S&ave with\nnew\npassword"),
tr("&Don't Save"),
0 // Enter == button 0
) )
{ // Escape == button 2
case 0: // Save clicked, Alt-S or Enter pressed.
// save
modified = false;
saveDocument(filename, FALSE);
exitZs (1);
break;
case 1: //
// Save with new password
modified = false;