mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 914190 - Use std::getline instead of C getline to parse /proc/N/maps. r=BenWa
Android's C getline (present in JB and up) calls libc's malloc directly, but its caller in Gecko is linked to jemalloc's free via mozglue; this caused a crash on profiler startup.
This commit is contained in:
parent
f21ef295e5
commit
d687166d14
@ -11,24 +11,10 @@
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include "platform.h"
|
||||
#include "shared-libraries.h"
|
||||
|
||||
#if !defined(__GLIBC__) && ANDROID_VERSION < 18
|
||||
/* a crapy version of getline, because it's not included in old bionics */
|
||||
static ssize_t getline(char **lineptr, size_t *n, FILE *stream)
|
||||
{
|
||||
char *ret;
|
||||
if (!*lineptr) {
|
||||
*lineptr = (char*)malloc(4096);
|
||||
}
|
||||
ret = fgets(*lineptr, 4096, stream);
|
||||
if (!ret)
|
||||
return 0;
|
||||
return strlen(*lineptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MOZ_WIDGET_GONK)
|
||||
// TODO fix me with proper include
|
||||
#include "nsDebug.h"
|
||||
@ -91,11 +77,10 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
||||
pid_t pid = getpid();
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, PATH_MAX, "/proc/%d/maps", pid);
|
||||
FILE *maps = fopen(path, "r");
|
||||
char *line = NULL;
|
||||
std::ifstream maps(path);
|
||||
std::string line;
|
||||
int count = 0;
|
||||
size_t line_size = 0;
|
||||
while (maps && getline (&line, &line_size, maps) > 0) {
|
||||
while (std::getline(maps, line)) {
|
||||
int ret;
|
||||
//XXX: needs input sanitizing
|
||||
unsigned long start;
|
||||
@ -103,7 +88,7 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
||||
char perm[6] = "";
|
||||
unsigned long offset;
|
||||
char name[PATH_MAX] = "";
|
||||
ret = sscanf(line,
|
||||
ret = sscanf(line.c_str(),
|
||||
"%lx-%lx %6s %lx %*s %*x %" PATH_MAX_STRING(PATH_MAX) "s\n",
|
||||
&start, &end, perm, &offset, name);
|
||||
if (!strchr(perm, 'x')) {
|
||||
@ -128,6 +113,5 @@ SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
||||
}
|
||||
count++;
|
||||
}
|
||||
free(line);
|
||||
return info;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user