Fix a bunch of minor issues found by Coverity. 42/209642/1
authorMichal Bloch <m.bloch@samsung.com>
Mon, 8 Jul 2019 14:49:34 +0000 (16:49 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 9 Jul 2019 12:23:28 +0000 (14:23 +0200)
Change-Id: I6dc3f56f1d590a6a49800d28ba78d3185555a837
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/livedumper/core.hpp
src/livedumper/livedumper.hpp
src/livedumper/program.hpp
src/shared/spawn.c

index 193577c..2f52efd 100644 (file)
@@ -136,6 +136,10 @@ class Core {
                                len = size;
 
                        ssize_t cur_pos = lseek64(input, 0, SEEK_CUR);
+                       if (cur_pos < 0) {
+                               logger.log_error("lseek error: %s", std::system_category().default_error_condition(errno).message());
+                               return;
+                       }
 
                        ssize_t bytes_read;
                        if ((bytes_read = read(input, buff, len)) == -1) {
index 6e0869a..01a2225 100644 (file)
@@ -47,9 +47,15 @@ class LiveDumper {
        Core<T> m_core;
        std::ofstream m_core_file;
        int prstatus_fd = -1;
+       std::pair <void *, size_t> map_buff;
 
  public:
-       explicit LiveDumper(const pid_t pid) : m_pid(pid) {}
+       explicit LiveDumper(const pid_t pid) : m_pid(pid), map_buff(MAP_FAILED, 0) {}
+
+       ~ LiveDumper () {
+               if (map_buff.first != MAP_FAILED)
+                       munmap(map_buff.first, map_buff.second);
+       }
 
        void CollectTpids() {
                m_tpids.clear();
@@ -148,14 +154,16 @@ class LiveDumper {
                memcpy(&prstatus.pr_reg, &registers, sizeof(prstatus.pr_reg));
                prstatus.pr_pid = m_pid;
 
-               auto buff = reinterpret_cast<char*>(mmap(nullptr, sizeof(prstatus),
+               map_buff.first = mmap(nullptr, sizeof(prstatus),
                                                         PROT_READ | PROT_WRITE,
                                                         MAP_SHARED,
                                                         prstatus_fd,
-                                                        0));
-               if (buff == MAP_FAILED)
+                                                        0);
+               if (map_buff.first == MAP_FAILED)
                        return;
-               memcpy(buff, &prstatus, sizeof(prstatus));
+               map_buff.second = sizeof prstatus;
+
+               memcpy(static_cast <char *> (map_buff.first), &prstatus, sizeof(prstatus));
        }
 
        void AddNotes(const std::vector<std::shared_ptr<MapRecord>> &records) {
index 855e7e4..f2eca7d 100644 (file)
@@ -30,6 +30,7 @@ class ProgramTableEntryBase {
                memset(&header, 0, sizeof(header));
                header.p_type = p_type;
        }
+       virtual ~ProgramTableEntryBase () {}
 };
 
 template <typename T>
index baca45d..392a053 100644 (file)
@@ -51,6 +51,9 @@ int spawn_setstderr(spawn_param_s *param)
 int spawn_nullstdfds(spawn_param_s *param)
 {
        int fd = open("/dev/null", O_RDWR);
+       if (fd < 0)
+               return -1;
+
        int ret = dup2(fd, STDIN_FILENO) < 0 || dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0 ? -1 : 0;
        if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO)
                close(fd);