From patchwork Thu Nov 7 02:44:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 3150651 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D6A9DBEEB2 for ; Thu, 7 Nov 2013 02:44:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 00D2220616 for ; Thu, 7 Nov 2013 02:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CA84205F5 for ; Thu, 7 Nov 2013 02:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753222Ab3KGCox (ORCPT ); Wed, 6 Nov 2013 21:44:53 -0500 Received: from m53-178.qiye.163.com ([123.58.178.53]:35868 "EHLO m53-178.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752667Ab3KGCow (ORCPT ); Wed, 6 Nov 2013 21:44:52 -0500 Received: from localhost.localdomain (unknown [222.240.177.34]) by m53-178.qiye.163.com (HMail) with ESMTPA id F18F813A825A; Thu, 7 Nov 2013 10:44:43 +0800 (CST) From: Li Wang To: Cc: Sage Weil , Li Wang Subject: [PATCH v2] Ceph: Fix memory leak in chain_flistxattr() Date: Thu, 7 Nov 2013 10:44:30 +0800 Message-Id: <1383792270-24537-1-git-send-email-liwang@ubuntukylin.com> X-Mailer: git-send-email 1.7.9.5 X-HM-Spam-Status: e1koWUFPN1dZCBgUCR5ZQUlJVU5MQkJCQkJJSExLTUtOTldZCQ4XHghZQV koKz0kKzooKCQyNSQzPjo*PilBS1VLQDYjJDU0JDI1JDM#Oj8#KUFOVUtAKy8pJCI#KCQyNSQzPj o*PilBS1VLQDg0LjUvKSIkODVBS1VLQCk#PDI0NSQ6KDI6QUtVS0ArKTQtMjU4PiQzLjU6NUFLVU tAPyI1OjYyOCQyKyQ1NCQyNSQzPjo*PilBS1VLQCk#OjckMiskMjUkKTk3JDI1JDM#Oj8#KUFKSV VLQDYuNy8yJCk4Ky8kPzI9PT4pPjUvJDI1JDM#Oj8#KUFJVUtAMiskLzQ*OiIkODUvJEskSktLQU tVS0AyKyROJDYyNS4vPiQ4NS8kSyRKS0FLVUtAMiskSEskNjI1Li8#JDg1LyRLJE5LQUtVS0AyKy RKJDM0LikkODUvJEskSktLQUtVS0AyKyRKJDYyNS4vPiQ4NS8kSyRKS0FLVUtAKC45JD5BSlVOTk A9NSQoLjkkPjUsNCk*KCQzNzEkSktLSUtKQUtVSUNAPTUkPSk#PiQzNzEkS0xLTktPQUpVTE5ZBg ++ X-HM-Sender-Digest: e1kSHx4VD1lBWUc6MQg6Cjo4LDo4EDorKjhIOj4qOkMwCjFVSlVKSENI TEJJSUNPSkNNVTMWGhIXVRcSDBoVHDsOGQ4VDw4QAhcSFVUYFBZFWVdZDB4ZWUEdGhcIHldZCAFZ QUpMS0k3V1kSC1lBWUlJSVVJT0tVSkxMVUhPWQY+ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Free allocated memory before return. Signed-off-by: Li Wang --- src/os/chain_xattr.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/os/chain_xattr.cc b/src/os/chain_xattr.cc index 8ca8156..c020c9d 100644 --- a/src/os/chain_xattr.cc +++ b/src/os/chain_xattr.cc @@ -388,6 +388,10 @@ done: int chain_flistxattr(int fd, char *names, size_t len) { int r; + char *p; + const char * end; + char *dest; + char *dest_end; if (!len) return sys_flistxattr(fd, names, len) * 2; @@ -403,12 +407,12 @@ int chain_flistxattr(int fd, char *names, size_t len) { r = sys_flistxattr(fd, full_buf, total_len); if (r < 0) - return r; + goto done; - char *p = full_buf; - const char *end = full_buf + r; - char *dest = names; - char *dest_end = names + len; + p = full_buf; + end = full_buf + r; + dest = names; + dest_end = names + len; while (p < end) { char name[CHAIN_XATTR_MAX_NAME_LEN * 2 + 16];