am 27123468: Use a simple replacement for String8 that allocates its storage beforehand to avoid reentering the heap while we\'re examining it (leak checker).
Merge commit '27123468b33cb61a1600079d583302b1b078b2ee' into eclair-mr2-plus-aosp * commit '27123468b33cb61a1600079d583302b1b078b2ee': Use a simple replacement for String8 that allocates its storage beforehand to avoid reentering the heap while we're examining it (leak checker).
This commit is contained in:
@@ -356,11 +356,44 @@ extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overallSize,
|
|||||||
size_t* infoSize, size_t* totalMemory, size_t* backtraceSize);
|
size_t* infoSize, size_t* totalMemory, size_t* backtraceSize);
|
||||||
extern "C" void free_malloc_leak_info(uint8_t* info);
|
extern "C" void free_malloc_leak_info(uint8_t* info);
|
||||||
|
|
||||||
|
// Use the String-class below instead of String8 to allocate all memory
|
||||||
|
// beforehand and not reenter the heap while we are examining it...
|
||||||
|
struct MyString8 {
|
||||||
|
static const size_t MAX_SIZE = 256 * 1024;
|
||||||
|
|
||||||
|
MyString8()
|
||||||
|
: mPtr((char *)malloc(MAX_SIZE)) {
|
||||||
|
*mPtr = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
~MyString8() {
|
||||||
|
free(mPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void append(const char *s) {
|
||||||
|
strcat(mPtr, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *string() const {
|
||||||
|
return mPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size() const {
|
||||||
|
return strlen(mPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char *mPtr;
|
||||||
|
|
||||||
|
MyString8(const MyString8 &);
|
||||||
|
MyString8 &operator=(const MyString8 &);
|
||||||
|
};
|
||||||
|
|
||||||
void memStatus(int fd, const Vector<String16>& args)
|
void memStatus(int fd, const Vector<String16>& args)
|
||||||
{
|
{
|
||||||
const size_t SIZE = 256;
|
const size_t SIZE = 256;
|
||||||
char buffer[SIZE];
|
char buffer[SIZE];
|
||||||
String8 result;
|
MyString8 result;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
Reference in New Issue
Block a user