From patchwork Tue Aug 20 16:31:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 2847187 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B142A9F239 for ; Tue, 20 Aug 2013 16:32:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B9152052A for ; Tue, 20 Aug 2013 16:32:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1417B20525 for ; Tue, 20 Aug 2013 16:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751226Ab3HTQbz (ORCPT ); Tue, 20 Aug 2013 12:31:55 -0400 Received: from mail-ee0-f44.google.com ([74.125.83.44]:40892 "EHLO mail-ee0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751129Ab3HTQby (ORCPT ); Tue, 20 Aug 2013 12:31:54 -0400 Received: by mail-ee0-f44.google.com with SMTP id b47so312616eek.17 for ; Tue, 20 Aug 2013 09:31:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding; bh=Nyn03BqB48jVS5X+Hgbj0EmNebGTv/jzvpscIg7KMiw=; b=QHeIDO4EQAkoX1e5cOBqvg0lremQ86Cw48hzbBoBvDXk96Y+tpnwDg6qAGfjkVAbml 9IOZC4Co7mAqIL2l609Psyvb1l5msaVxP1s5Z7Q7o0ExiZFP6BQLSHRy2zFIxlpY8KR9 Fp3UEmy0c9JGRtvuQKC6/NfAzO6enKmBI5JecnbFohGfIMgK7kg1fwmxC40jKKx44bp1 ils2l6TawYaLyXpbZJquf7kT6wKhwN2mazqVcle/4F4x2Gk8q/HiECQcMIEed6ClwTK+ uC3MSL80rzIbpsjiFSRN8oJ9SVAfj9EPtmj73Yo0vjJqNDpVAkLgIJJXIIF1CkPV/UZX LdqA== X-Gm-Message-State: ALoCoQnwcat9yolK+3oRCH4QXYWU6HjEmWbkbw3P7OXx+Y4VdRwuO+6EV+jlbVz8X6tHZ5VKL7OC X-Received: by 10.14.88.65 with SMTP id z41mr3347675eee.38.1377016312758; Tue, 20 Aug 2013 09:31:52 -0700 (PDT) Received: from [192.168.1.102] (c-98-229-118-119.hsd1.ma.comcast.net. [98.229.118.119]) by mx.google.com with ESMTPSA id r48sm3432551eev.14.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Aug 2013 09:31:52 -0700 (PDT) Message-ID: <521399F6.3040209@dev.mellanox.co.il> Date: Tue, 20 Aug 2013 12:31:50 -0400 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: "linux-rdma (linux-rdma@vger.kernel.org)" CC: Dan Ben-Yosef , Vladimir Koushnir Subject: [PATCH opensm] osm_db_files.c : Fix resource leak guid2lid parser Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Dan Ben Yosef leaks the storage that "p_accum_val" and "p_key" points to. Signed-off-by: Dan Ben Yosef Reviewed-by: Vladimir Koushnir Signed-off-by: Hal Rosenstock --- -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/opensm/osm_db_files.c b/opensm/osm_db_files.c index 0d8f36c..513cf85 100644 --- a/opensm/osm_db_files.c +++ b/opensm/osm_db_files.c @@ -272,7 +272,7 @@ int osm_db_restore(IN osm_db_domain_t * p_domain) boolean_t before_key; char *p_first_word, *p_rest_of_line, *p_last; char *p_key = NULL; - char *p_prev_val, *p_accum_val = NULL; + char *p_prev_val = NULL, *p_accum_val = NULL; char *endptr = NULL; unsigned int line_num; @@ -371,12 +371,18 @@ int osm_db_restore(IN osm_db_domain_t * p_domain) if (st_lookup(p_domain_imp->p_hash, (st_data_t) p_key, (void *)&p_prev_val)) { + /* if previously used we ignore this guid */ OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6106: " "Key:%s already exists in:%s with value:%s." " Removing it\n", p_key, p_domain_imp->file_name, p_prev_val); + free(p_key); + p_key = NULL; + free(p_accum_val); + p_accum_val = NULL; + continue; } else { p_prev_val = NULL; } @@ -391,6 +397,10 @@ int osm_db_restore(IN osm_db_domain_t * p_domain) OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 610B: " "Key:%s is invalid\n", p_key); + free(p_key); + p_key = NULL; + free(p_accum_val); + p_accum_val = NULL; } else { /* store our key and value */ st_insert(p_domain_imp->p_hash, @@ -404,6 +414,7 @@ int osm_db_restore(IN osm_db_domain_t * p_domain) strlen(sLine) + 1); strcpy(p_accum_val, p_prev_val); free(p_prev_val); + p_prev_val = NULL; strcat(p_accum_val, sLine); } } /* in key */