Merge "Fix some memory leaks."
This commit is contained in:
+5
-5
@@ -124,20 +124,20 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache) {
|
|||||||
// - the name of the package zip file.
|
// - the name of the package zip file.
|
||||||
//
|
//
|
||||||
|
|
||||||
const char** args = (const char**)malloc(sizeof(char*) * 5);
|
const char* args[5];
|
||||||
args[0] = binary;
|
args[0] = binary;
|
||||||
args[1] = EXPAND(RECOVERY_API_VERSION); // defined in Android.mk
|
args[1] = EXPAND(RECOVERY_API_VERSION); // defined in Android.mk
|
||||||
char* temp = (char*)malloc(10);
|
char temp[16];
|
||||||
sprintf(temp, "%d", pipefd[1]);
|
snprintf(temp, sizeof(temp), "%d", pipefd[1]);
|
||||||
args[2] = temp;
|
args[2] = temp;
|
||||||
args[3] = (char*)path;
|
args[3] = path;
|
||||||
args[4] = NULL;
|
args[4] = NULL;
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
umask(022);
|
umask(022);
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
execv(binary, (char* const*)args);
|
execv(binary, const_cast<char**>(args));
|
||||||
fprintf(stdout, "E:Can't run %s (%s)\n", binary, strerror(errno));
|
fprintf(stdout, "E:Can't run %s (%s)\n", binary, strerror(errno));
|
||||||
_exit(-1);
|
_exit(-1);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-13
@@ -28,6 +28,7 @@
|
|||||||
#include <linux/fb.h>
|
#include <linux/fb.h>
|
||||||
#include <linux/kd.h>
|
#include <linux/kd.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
#include "minui.h"
|
#include "minui.h"
|
||||||
@@ -398,18 +399,13 @@ int res_create_localized_alpha_surface(const char* name,
|
|||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = NULL;
|
||||||
png_uint_32 width, height;
|
png_uint_32 width, height;
|
||||||
png_byte channels;
|
png_byte channels;
|
||||||
unsigned char* row;
|
|
||||||
png_uint_32 y;
|
png_uint_32 y;
|
||||||
|
std::vector<unsigned char> row;
|
||||||
|
|
||||||
*pSurface = NULL;
|
*pSurface = NULL;
|
||||||
|
|
||||||
if (locale == NULL) {
|
if (locale == NULL) {
|
||||||
surface = malloc_surface(0);
|
return result;
|
||||||
surface->width = 0;
|
|
||||||
surface->height = 0;
|
|
||||||
surface->row_bytes = 0;
|
|
||||||
surface->pixel_bytes = 1;
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
|
result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
|
||||||
@@ -420,13 +416,13 @@ int res_create_localized_alpha_surface(const char* name,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = reinterpret_cast<unsigned char*>(malloc(width));
|
row.resize(width);
|
||||||
for (y = 0; y < height; ++y) {
|
for (y = 0; y < height; ++y) {
|
||||||
png_read_row(png_ptr, row, NULL);
|
png_read_row(png_ptr, row.data(), NULL);
|
||||||
int w = (row[1] << 8) | row[0];
|
int w = (row[1] << 8) | row[0];
|
||||||
int h = (row[3] << 8) | row[2];
|
int h = (row[3] << 8) | row[2];
|
||||||
int len = row[4];
|
int len = row[4];
|
||||||
char* loc = (char*)row+5;
|
char* loc = reinterpret_cast<char*>(&row[5]);
|
||||||
|
|
||||||
if (y+1+h >= height || matches_locale(loc, locale)) {
|
if (y+1+h >= height || matches_locale(loc, locale)) {
|
||||||
printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
|
printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
|
||||||
@@ -443,8 +439,8 @@ int res_create_localized_alpha_surface(const char* name,
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < h; ++i, ++y) {
|
for (i = 0; i < h; ++i, ++y) {
|
||||||
png_read_row(png_ptr, row, NULL);
|
png_read_row(png_ptr, row.data(), NULL);
|
||||||
memcpy(surface->data + i*w, row, w);
|
memcpy(surface->data + i*w, row.data(), w);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pSurface = reinterpret_cast<GRSurface*>(surface);
|
*pSurface = reinterpret_cast<GRSurface*>(surface);
|
||||||
@@ -452,7 +448,7 @@ int res_create_localized_alpha_surface(const char* name,
|
|||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < h; ++i, ++y) {
|
for (i = 0; i < h; ++i, ++y) {
|
||||||
png_read_row(png_ptr, row, NULL);
|
png_read_row(png_ptr, row.data(), NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
|
|||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
Hash.c \
|
Hash.c \
|
||||||
SysUtil.c \
|
SysUtil.c \
|
||||||
DirUtil.c \
|
DirUtil.cpp \
|
||||||
Inlines.c \
|
Inlines.c \
|
||||||
Zip.c
|
Zip.c
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "DirUtil.h"
|
#include "DirUtil.h"
|
||||||
|
|
||||||
typedef enum { DMISSING, DDIR, DILLEGAL } DirStatus;
|
typedef enum { DMISSING, DDIR, DILLEGAL } DirStatus;
|
||||||
@@ -66,43 +68,25 @@ dirCreateHierarchy(const char *path, int mode,
|
|||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// Allocate a path that we can modify; stick a slash on
|
||||||
/* Allocate a path that we can modify; stick a slash on
|
// the end to make things easier.
|
||||||
* the end to make things easier.
|
std::string cpath = path;
|
||||||
*/
|
|
||||||
size_t pathLen = strlen(path);
|
|
||||||
char *cpath = (char *)malloc(pathLen + 2);
|
|
||||||
if (cpath == NULL) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(cpath, path, pathLen);
|
|
||||||
if (stripFileName) {
|
if (stripFileName) {
|
||||||
/* Strip everything after the last slash.
|
// Strip everything after the last slash.
|
||||||
*/
|
size_t pos = cpath.rfind('/');
|
||||||
char *c = cpath + pathLen - 1;
|
if (pos == std::string::npos) {
|
||||||
while (c != cpath && *c != '/') {
|
|
||||||
c--;
|
|
||||||
}
|
|
||||||
if (c == cpath) {
|
|
||||||
//xxx test this path
|
|
||||||
/* No directory component. Act like the path was empty.
|
|
||||||
*/
|
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
free(cpath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
c[1] = '\0'; // Terminate after the slash we found.
|
cpath.resize(pos + 1);
|
||||||
} else {
|
} else {
|
||||||
/* Make sure that the path ends in a slash.
|
// Make sure that the path ends in a slash.
|
||||||
*/
|
cpath.push_back('/');
|
||||||
cpath[pathLen] = '/';
|
|
||||||
cpath[pathLen + 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if it already exists.
|
/* See if it already exists.
|
||||||
*/
|
*/
|
||||||
ds = getPathDirStatus(cpath);
|
ds = getPathDirStatus(cpath.c_str());
|
||||||
if (ds == DDIR) {
|
if (ds == DDIR) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (ds == DILLEGAL) {
|
} else if (ds == DILLEGAL) {
|
||||||
@@ -112,7 +96,8 @@ dirCreateHierarchy(const char *path, int mode,
|
|||||||
/* Walk up the path from the root and make each level.
|
/* Walk up the path from the root and make each level.
|
||||||
* If a directory already exists, no big deal.
|
* If a directory already exists, no big deal.
|
||||||
*/
|
*/
|
||||||
char *p = cpath;
|
const char *path_start = &cpath[0];
|
||||||
|
char *p = &cpath[0];
|
||||||
while (*p != '\0') {
|
while (*p != '\0') {
|
||||||
/* Skip any slashes, watching out for the end of the string.
|
/* Skip any slashes, watching out for the end of the string.
|
||||||
*/
|
*/
|
||||||
@@ -135,12 +120,11 @@ dirCreateHierarchy(const char *path, int mode,
|
|||||||
/* Check this part of the path and make a new directory
|
/* Check this part of the path and make a new directory
|
||||||
* if necessary.
|
* if necessary.
|
||||||
*/
|
*/
|
||||||
ds = getPathDirStatus(cpath);
|
ds = getPathDirStatus(path_start);
|
||||||
if (ds == DILLEGAL) {
|
if (ds == DILLEGAL) {
|
||||||
/* Could happen if some other process/thread is
|
/* Could happen if some other process/thread is
|
||||||
* messing with the filesystem.
|
* messing with the filesystem.
|
||||||
*/
|
*/
|
||||||
free(cpath);
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (ds == DMISSING) {
|
} else if (ds == DMISSING) {
|
||||||
int err;
|
int err;
|
||||||
@@ -148,11 +132,11 @@ dirCreateHierarchy(const char *path, int mode,
|
|||||||
char *secontext = NULL;
|
char *secontext = NULL;
|
||||||
|
|
||||||
if (sehnd) {
|
if (sehnd) {
|
||||||
selabel_lookup(sehnd, &secontext, cpath, mode);
|
selabel_lookup(sehnd, &secontext, path_start, mode);
|
||||||
setfscreatecon(secontext);
|
setfscreatecon(secontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = mkdir(cpath, mode);
|
err = mkdir(path_start, mode);
|
||||||
|
|
||||||
if (secontext) {
|
if (secontext) {
|
||||||
freecon(secontext);
|
freecon(secontext);
|
||||||
@@ -160,22 +144,17 @@ dirCreateHierarchy(const char *path, int mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
free(cpath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (timestamp != NULL && utime(cpath, timestamp)) {
|
if (timestamp != NULL && utime(path_start, timestamp)) {
|
||||||
free(cpath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else, this directory already exists.
|
// else, this directory already exists.
|
||||||
|
|
||||||
/* Repair the path and continue.
|
// Repair the path and continue.
|
||||||
*/
|
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
free(cpath);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user