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

Commit 7fdc80f6 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Fix incorrect closing of fds.

Test: Ran unit tests without fdsan aborts.
Change-Id: I4a060739c61e93364b9aabe3ae1d6cbc3639d310
parent 91a53189
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#include <inttypes.h>
#include <inttypes.h>
#include <linux/dma-buf.h>
#include <linux/dma-buf.h>
#include <poll.h>
#include <poll.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
@@ -230,7 +231,7 @@ class DmaBufTester : public ::testing::Test {
    DmaBufTester() : ion_fd(ion_open()), ion_heap_mask(get_ion_heap_mask()) {}
    DmaBufTester() : ion_fd(ion_open()), ion_heap_mask(get_ion_heap_mask()) {}


    ~DmaBufTester() {
    ~DmaBufTester() {
        if (is_valid()) {
        if (ion_fd >= 0) {
            ion_close(ion_fd);
            ion_close(ion_fd);
        }
        }
    }
    }
@@ -241,12 +242,16 @@ class DmaBufTester : public ::testing::Test {
        int fd;
        int fd;
        int err = ion_alloc_fd(ion_fd, size, 0, ion_heap_mask, 0, &fd);
        int err = ion_alloc_fd(ion_fd, size, 0, ion_heap_mask, 0, &fd);
        if (err < 0) {
        if (err < 0) {
            return unique_fd{err};
            printf("Failed ion_alloc_fd, return value: %d\n", err);
            return unique_fd{};
        }
        }


        if (!name.empty()) {
        if (!name.empty()) {
            err = ioctl(fd, DMA_BUF_SET_NAME, name.c_str());
            if (ioctl(fd, DMA_BUF_SET_NAME, name.c_str()) == -1) {
            if (err < 0) return unique_fd{-errno};
                printf("Failed ioctl(DMA_BUF_SET_NAME): %s\n", strerror(errno));
                close(fd);
                return unique_fd{};
            }
        }
        }


        return unique_fd{fd};
        return unique_fd{fd};
@@ -306,7 +311,7 @@ class DmaBufTester : public ::testing::Test {
        return ret;
        return ret;
    }
    }


    unique_fd ion_fd;
    int ion_fd;
    const int ion_heap_mask;
    const int ion_heap_mask;
};
};