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:
parent
781a715529
commit
b40802973a
|
@ -13,6 +13,8 @@
|
||||||
#include <stdio.h> // for SEEK_* defines
|
#include <stdio.h> // for SEEK_* defines
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
using namespace BPrivate::Storage::Sniffer;
|
using namespace BPrivate::Storage::Sniffer;
|
||||||
|
|
||||||
Pattern::Pattern(const std::string &string, const std::string &mask)
|
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();
|
off_t len = fString.length();
|
||||||
char *buffer = new(nothrow) char[len+1];
|
char *buffer = new(nothrow) char[len+1];
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
|
ArrayDeleter<char> _(buffer);
|
||||||
ssize_t bytesRead = data->ReadAt(start, buffer, len);
|
ssize_t bytesRead = data->ReadAt(start, buffer, len);
|
||||||
// \todo If there are fewer bytes left in the data stream
|
// \todo If there are fewer bytes left in the data stream
|
||||||
// from the given position than the length of our data
|
// 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();
|
off_t len = fString.length();
|
||||||
char *buffer = new(std::nothrow) char[len+1];
|
char *buffer = new(std::nothrow) char[len+1];
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
|
ArrayDeleter<char> _(buffer);
|
||||||
ssize_t bytesRead = data->ReadAt(start, buffer, len);
|
ssize_t bytesRead = data->ReadAt(start, buffer, len);
|
||||||
// \todo If there are fewer bytes left in the data stream
|
// \todo If there are fewer bytes left in the data stream
|
||||||
// from the given position than the length of our data
|
// from the given position than the length of our data
|
||||||
|
|
|
@ -171,6 +171,7 @@ SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
err = B_NO_MEMORY;
|
err = B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!err)
|
if (!err)
|
||||||
err = file.SetTo(ref, B_READ_ONLY);
|
err = file.SetTo(ref, B_READ_ONLY);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
@ -183,6 +184,8 @@ SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
|
||||||
if (!err)
|
if (!err)
|
||||||
err = GuessMimeType(&file, buffer, bytes, type);
|
err = GuessMimeType(&file, buffer, bytes, type);
|
||||||
|
|
||||||
|
delete[] buffer;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue