From patchwork Wed Apr 15 15:04:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 3468 Return-Path: Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7A6D62E35 for ; Wed, 15 Apr 2020 17:04:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="FMA4ts4p"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=igqKtmU9R/gVFk9I7l20auMWyLmlsLFGtzLi0TNLEnk=; b=FMA4ts4pNWyS3gannIz5Y9tZUHBrEyBzWGU55qrbCsDRGQyyYftWYmdsmnYqozWs39CF EtnYnc4fLiZijQOg/lqj8cBVRIa0IAScyXigTW7ZhFPALVencKsmRZlbTobVQNMJdtuvsg Ffmv8cWSLUO2t0MthW0lUI4HDUsguPjbY= Received: by filterdrecv-p3iad2-8ddf98858-4rnwn with SMTP id filterdrecv-p3iad2-8ddf98858-4rnwn-19-5E97226E-11 2020-04-15 15:04:14.332166651 +0000 UTC m=+1778209.186877990 Received: from mail.uajain.com (unknown) by ismtpd0003p1maa1.sendgrid.net (SG) with ESMTP id qiH5KXC1QbibuDzsa_54lQ Wed, 15 Apr 2020 15:04:13.927 +0000 (UTC) From: Umang Jain Date: Wed, 15 Apr 2020 15:04:14 +0000 (UTC) Message-Id: <20200415150409.27938-2-email@uajain.com> In-Reply-To: <20200415150409.27938-1-email@uajain.com> References: <20200415150409.27938-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc4om/Oij3lMEQBxKPi/30O4MUN2cHtcUTKTK91M24p1f7vvUOd0VY77AWX2BK8X3j0dlslJ53foXH1NojjJYnYUus+UEc7JW28mLxJZC4V6OeaKeoUZEpPRLF5qSJdQonsu+/7zl5YTs8H7F/+fQ32eaGryCU7nvfjJ55BT+VVfdT6mHUywRByTbtlUcfjms3tR1j9JzDbUmkHxv/gYLCkA== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v2 1/2] test: ipc: unixsocket: Close open fds on error paths X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 15:04:16 -0000 Pointed out by Coverity DefectId=279052 Signed-off-by: Umang Jain --- test/ipc/unixsocket.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp index 5348f35..7bc6a89 100644 --- a/test/ipc/unixsocket.cpp +++ b/test/ipc/unixsocket.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include "ipc_unixsocket.h" @@ -467,18 +468,22 @@ private: if (fd < 0) return fd; + FileDescriptor file_desc = FileDescriptor(fd); + close(fd); + if (file_desc.fd() < 0) + return file_desc.fd(); + int size = 0; for (unsigned int i = 0; i < num; i++) { - int clone = dup(fd); - if (clone < 0) - return clone; + FileDescriptor *clone = new FileDescriptor(file_desc.fd()); + int clone_int = clone->fd(); + if (clone_int < 0) + return clone_int; - size += calculateLength(clone); - message->fds.push_back(clone); + size += calculateLength(clone_int); + message->fds.push_back(clone_int); } - close(fd); - return size; } From patchwork Wed Apr 15 15:04:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 3469 Return-Path: Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0193762E7D for ; Wed, 15 Apr 2020 17:04:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="RiHcbE2A"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=s1; bh=yLO2Ckgnl1QQ8BefJTWsMy9vFKnYm1mlGdBdB3rsQ48=; b=RiHcbE2AMCX/4J2GX4MeG6KOQtvwol0l/LndUb7fpa4syevG98MoqSpqkWukXT9DTFzW 0vk5jcHrTJss8mndB/wBiNl149rnKDgyuL0/azuPUxI/j8bxNwdj1Ysnd6lkjTorXqB1jr uoDi8XN9kLFJO9UtZwF1188/pCDUyPTfI= Received: by filterdrecv-p3iad2-8ddf98858-xm5rk with SMTP id filterdrecv-p3iad2-8ddf98858-xm5rk-18-5E97226F-55 2020-04-15 15:04:15.66506489 +0000 UTC m=+1701644.644798356 Received: from mail.uajain.com (unknown) by ismtpd0002p1maa1.sendgrid.net (SG) with ESMTP id YohL4mBUR4mpvsSu3QMkQw Wed, 15 Apr 2020 15:04:15.244 +0000 (UTC) From: Umang Jain Date: Wed, 15 Apr 2020 15:04:15 +0000 (UTC) Message-Id: <20200415150409.27938-3-email@uajain.com> In-Reply-To: <20200415150409.27938-1-email@uajain.com> References: <20200415150409.27938-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPc0FyoEBOIv1fDR+9klxGaYh30+uRN54fa80X9vZwKmOrF4YaSczosUgd99f4wth7bxJ0TDP4k68merFctph844TY+q+MFM3Fqgfb1oSlZBOrwVVB8uR47xlDupPacc4k2ErWDx1QXJWcJ8a8Gk0A3+yojLQi0aSGpAR6YSIH5DxET63dCxo7Terr32gieXvvROsWiCmP9eD0bqVbgSQ8BsQ== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v2 2/2] test: log: log_api: Close open fds on error paths X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 15:04:18 -0000 Pointed out by Coverity DefectId=279091 Signed-off-by: Umang Jain --- test/log/log_api.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp index 33622f8..4d2c8db 100644 --- a/test/log/log_api.cpp +++ b/test/log/log_api.cpp @@ -86,6 +86,7 @@ protected: if (logSetFile(path) < 0) { cerr << "Failed to set log file" << endl; + close(fd); return TestFail; } @@ -96,6 +97,7 @@ protected: lseek(fd, 0, SEEK_SET); if (read(fd, buf, sizeof(buf)) < 0) { cerr << "Failed to read tmp log file" << endl; + close(fd); return TestFail; } close(fd);