From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9B8C63856265 for ; Sat, 28 May 2022 10:11:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B8C63856265 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-CWDSbPMtN52cNL0lcD1fYQ-1; Sat, 28 May 2022 06:11:03 -0400 X-MC-Unique: CWDSbPMtN52cNL0lcD1fYQ-1 Received: by mail-ed1-f70.google.com with SMTP id o8-20020aa7d3c8000000b0042c598de9f3so2902959edr.4 for ; Sat, 28 May 2022 03:11:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=wxA5aUx4mDhALaOfSOalqE6Yj9so6WV5kyTee1DIpNM=; b=XVsIzBJMNQ2l42DmycTC55UCdYyTNfzasEll60KYK7yvWHXySQmSih6krkU1pWwCQj DSoI6S0cR9rVmdzT/S1KaKYPhHWhbXSMmcwaKrOL5mBGoeetbs8F8N4IotBnKzjNbqY2 oPn6qX2sHzMJpuVQkv/vYEMr6ZTMddyI74v8dMJC4ROPNXs+w0Zah6WarkFRgyXdrF3k TVNfAHqM0c4nxhkRGQZ4h5MB91qLthbz9Hso9L3LoILXzjOm1T4+dOEaEO7DYHk8c0o4 Ox1koSgrYsHKhr9pKFVqKIhdAvQD93YR4ml/OrU3ySSYzgIgYAyJXQ0yFFHYMIzXT6Am ug5Q== X-Gm-Message-State: AOAM530qeCRoXryAFIKxysaSRnJBtVul++MhRsOmxqI7OHI1T9dV1d3b hdIgqygpFY+Qdne2+mRhanMJksk4cxUWtrT9a3qhr3bFEzuQ5D2VwNm8u52pUVUk6SJRyD1vQWc lnKYupVetNqybMVfcF1sz9g== X-Received: by 2002:a05:6402:1a33:b0:42d:6ba1:f660 with SMTP id be19-20020a0564021a3300b0042d6ba1f660mr4924560edb.359.1653732661773; Sat, 28 May 2022 03:11:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym5/uNtPO13lEAwjDndZLMqFETdS6uk2iULL0PPx7lhNFMUum738f+JQ+qHljBT2+LfCZ1ng== X-Received: by 2002:a05:6402:1a33:b0:42d:6ba1:f660 with SMTP id be19-20020a0564021a3300b0042d6ba1f660mr4924552edb.359.1653732661589; Sat, 28 May 2022 03:11:01 -0700 (PDT) Received: from localhost (92.40.179.17.threembb.co.uk. [92.40.179.17]) by smtp.gmail.com with ESMTPSA id c2-20020a17090603c200b006fea59ef3a5sm2262647eja.32.2022.05.28.03.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 03:11:00 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , Andrew Burgess via Gdb-patches Subject: Re: [PATCH 1/2] gdb: use gdb::unique_xmalloc_ptr for docs in cmdpy_init In-Reply-To: <87ilps6vg6.fsf@tromey.com> References: <31151a0451266a6dd2a4c01e4a60795596ad2077.1652784658.git.aburgess@redhat.com> <87ilps6vg6.fsf@tromey.com> Date: Sat, 28 May 2022 11:10:59 +0100 Message-ID: <877d66ezm4.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2022 10:11:08 -0000 Tom Tromey writes: >>>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: > > Andrew> Make use of gdb::unique_xmalloc_ptr to hold the documentation > Andrew> string in cmdpy_init (when creating a custom GDB command in Python). > Andrew> I think this is all pretty straight forward, the only slight weirdness > Andrew> is the removal of the call to free toward the end of this function. > > Andrew> Prior to this commit, if an exception was thrown after the GDB command > Andrew> was created then we would (I think) end up freeing the documentation > Andrew> string even though the command would remain registered with GDB, which > Andrew> would surely lead to undefined behaviour. > > Andrew> After this commit we release the doc string at the point that we hand > Andrew> it over to the command creation routines. If we throw _after_ the > Andrew> command has been created within GDB then the doc string will be left > Andrew> live. If we throw during the command creation itself (either from > Andrew> add_prefix_cmd or add_cmd) then it is up to those functions to free > Andrew> the doc string (I suspect we don't, but I think in general the > Andrew> commands are pretty bad at cleaning up after themselves, so I don't > Andrew> think this is a huge problem). > > This looks ok to me. > Maybe an add_prefix_cmd overload that takes a unique_xmalloc_ptr would > be the way to go eventually. I agree being able to pass a unique_xmalloc_ptr to the commands would improve things. That said, I've pushed this patch as is for now, as I feel improving the memory management for cmds is a bigger, separate, task. Thanks, Andrew