Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48cd4132 authored by Chih-hung Hsieh's avatar Chih-hung Hsieh Committed by Gerrit Code Review
Browse files

Merge "Fix potential memory leaks"

parents d3484c84 784e63c9
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include <sys/prctl.h>
#include <unistd.h>
#include <iostream>
#include <string>

#define SECTOR_SIZE ((__u64)512)
#define BUFFER_BYTES 4096
@@ -133,16 +134,16 @@ int not_splice(int from, int to, __u64 count) {
    return 0;
}

int simple_daemon(char* control_path, char* backing_path) {
    int control_fd = open(control_path, O_RDWR);
static int simple_daemon(const std::string& control_path, const std::string& backing_path) {
    int control_fd = open(control_path.c_str(), O_RDWR);
    if (control_fd < 0) {
        fprintf(stderr, "Unable to open control device %s\n", control_path);
        fprintf(stderr, "Unable to open control device %s\n", control_path.c_str());
        return -1;
    }

    int backing_fd = open(backing_path, O_RDWR);
    int backing_fd = open(backing_path.c_str(), O_RDWR);
    if (backing_fd < 0) {
        fprintf(stderr, "Unable to open backing device %s\n", backing_path);
        fprintf(stderr, "Unable to open backing device %s\n", backing_path.c_str());
        return -1;
    }

@@ -286,8 +287,8 @@ void usage(char* prog) {
}

int main(int argc, char* argv[]) {
    char* control_path = NULL;
    char* backing_path = NULL;
    std::string control_path;
    std::string backing_path;
    char* store;
    int c;

@@ -299,10 +300,10 @@ int main(int argc, char* argv[]) {
                usage(basename(argv[0]));
                exit(0);
            case 'c':
                control_path = strdup(optarg);
                control_path = optarg;
                break;
            case 'b':
                backing_path = strdup(optarg);
                backing_path = optarg;
                break;
            case 'v':
                verbose = true;
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <sys/prctl.h>
#include <time.h>
#include <unistd.h>
#include <memory>

int MaybeDowngrade() {
    int res = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
@@ -58,7 +59,7 @@ int main(int argc, char** argv) {
        // Disallow automatic upgrade from ASYNC mode.
        if (prctl(PR_SET_TAGGED_ADDR_CTRL, res & ~PR_MTE_TCF_SYNC, 0, 0, 0) == -1) abort();
    }
    volatile char* f = (char*)malloc(1);
    std::unique_ptr<volatile char[]> f(new char[1]);
    f[17] = 'x';
    char buf[1];
    read(1, buf, 1);