Addressed memory leaks in the MIME sniffer code. Fixes bug #1660.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24604 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-03-27 04:26:43 +00:00
parent 781a715529
commit b40802973a
2 changed files with 10 additions and 3 deletions

View File

@ -13,6 +13,8 @@
#include <stdio.h> // for SEEK_* defines
#include <new>
#include <AutoDeleter.h>
using namespace BPrivate::Storage::Sniffer;
Pattern::Pattern(const std::string &string, const std::string &mask)
@ -115,6 +117,7 @@ Pattern::Sniff(off_t start, off_t size, BPositionIO *data, bool caseInsensitive)
off_t len = fString.length();
char *buffer = new(nothrow) char[len+1];
if (buffer) {
ArrayDeleter<char> _(buffer);
ssize_t bytesRead = data->ReadAt(start, buffer, len);
// \todo If there are fewer bytes left in the data stream
// from the given position than the length of our data
@ -160,6 +163,7 @@ Pattern::Sniff(off_t start, off_t size, BPositionIO *data, bool caseInsensitive)
off_t len = fString.length();
char *buffer = new(std::nothrow) char[len+1];
if (buffer) {
ArrayDeleter<char> _(buffer);
ssize_t bytesRead = data->ReadAt(start, buffer, len);
// \todo If there are fewer bytes left in the data stream
// from the given position than the length of our data

View File

@ -163,14 +163,15 @@ SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
if (bytes < 0)
err = bytes;
}
// Next read that many bytes (or fewer, if the file isn't
// that long) into a buffer
if (!err) {
buffer = new(std::nothrow) char[bytes];
if (!buffer)
err = B_NO_MEMORY;
}
}
if (!err)
err = file.SetTo(ref, B_READ_ONLY);
if (!err) {
@ -182,7 +183,9 @@ SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
// Now sniff the buffer
if (!err)
err = GuessMimeType(&file, buffer, bytes, type);
delete[] buffer;
return err;
}