From patchwork Mon Feb 25 22:36:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2182941 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 498E2DF230 for ; Mon, 25 Feb 2013 22:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932379Ab3BYWgb (ORCPT ); Mon, 25 Feb 2013 17:36:31 -0500 Received: from mail-ie0-f181.google.com ([209.85.223.181]:54681 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932231Ab3BYWga (ORCPT ); Mon, 25 Feb 2013 17:36:30 -0500 Received: by mail-ie0-f181.google.com with SMTP id 17so3668112iea.40 for ; Mon, 25 Feb 2013 14:36:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding:x-gm-message-state; bh=uqKkCpxeEMsrBGp8KezETq8GDQ7xmsFDn1SUBtHX3sE=; b=Lu6khtQXSl1HrlUdS2LdioqVX88nqToJN8qn0DLtiAKbgEJmHt/bvWi/EXdoHFDTcO H+xX8ktxRBJnDdjZdFCIU0iV/ALUBA0d+/t6eUdLo1AdIjRmZe06jEiVHiuhjkmDVEJT 81RtsSltpiODq2aqGiGMp1KNIU6lRfkabnqMmcEsyk2J9N4CYIPLy7Pl9mNWjmsp6Ifc sPOYqA3Obkgi619qvRHRKYGUInDY2xnNlHA+e+hBEnXKUA9A1P9hI3D3ePws0LKui7Xa cdEHAuagzixLkKGNlUV1xLiUpNSoycrgrnu4rlG06wIPjtFaYjJ03k3bqOI44hS3y08f dm9A== X-Received: by 10.43.4.74 with SMTP id ob10mr4128804icb.28.1361831790201; Mon, 25 Feb 2013 14:36:30 -0800 (PST) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id wo8sm6264099igb.6.2013.02.25.14.36.28 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Feb 2013 14:36:29 -0800 (PST) Message-ID: <512BE76B.5040104@inktank.com> Date: Mon, 25 Feb 2013 16:36:27 -0600 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: "ceph-devel@vger.kernel.org" Subject: [PATCH] libceph: fix a osd request memory leak X-Gm-Message-State: ALoCoQnF8EURrpZcMix9klqqd6NCbteLjPwlC0aXYNA0WuQnpFyeRXKr3+mMB2yXtz8dZeeWuINV Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org If an invalid layout is provided to ceph_osdc_new_request(), its call to calc_layout() might return an error. At that point in the function we've already allocated an osd request structure, so we need to free it (drop a reference) in the event such an error occurs. The only other value calc_layout() will return is 0, so make that explicit in the successful case. This resolves: http://tracker.ceph.com/issues/4240 Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- net/ceph/osd_client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) /* in case it differs from natural (file) alignment that diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 39629b6..5daced2 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -109,7 +109,7 @@ static int calc_layout(struct ceph_vino vino, snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno); req->r_oid_len = strlen(req->r_oid); - return r; + return 0; } /* @@ -437,8 +437,10 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, /* calculate max write size */ r = calc_layout(vino, layout, off, plen, req, ops); - if (r < 0) + if (r < 0) { + ceph_osdc_put_request(req); return ERR_PTR(r); + } req->r_file_layout = *layout; /* keep a copy */