From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22560 invoked by alias); 15 Apr 2011 07:40:24 -0000 Received: (qmail 22541 invoked by uid 22791); 15 Apr 2011 07:40:22 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.152) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Apr 2011 07:40:17 +0000 Received: from md1.u-strasbg.fr (md1.u-strasbg.fr [IPv6:2001:660:2402::186]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p3F7e8tO017634 ; Fri, 15 Apr 2011 09:40:08 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms4.u-strasbg.fr [130.79.204.13]) by md1.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p3F7e7Z4016604 ; Fri, 15 Apr 2011 09:40:07 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p3F7e6TE026928 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) ; Fri, 15 Apr 2011 09:40:06 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'Tom Tromey'" Cc: , "'Maxim Grigoriev'" References: <15837.6740910628$1302342165@news.gmane.org> In-Reply-To: Subject: [RFA-v2] xtensa-tdep.c ARI fixes Date: Fri, 15 Apr 2011 07:40:00 -0000 Message-ID: <005701cbfb40$57308f30$0591ad90$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-04/txt/msg00221.txt.bz2 > Pierre> The only non-trivial change is in xtensa_register_type: > Pierre> this is mainly because I do not understand the old code: > Pierre> it was using both xmalloc and strdup, which should > Pierre> create a memory leak, no? > Pierre> But maybe I miss something? > > I agree. > > Pierre> - char *name = xmalloc (16); > Pierre> + char *name = xstrprintf ("int%d", size * 8); > > Looks better. > > Pierre> + = arch_integer_type (gdbarch, size * 8, 1, name); > > arch_integer_type calls arch_type, which calls xstrdup(name). > So I think you need to xfree name here. Here is a new version that adds this xfree call. Could someone test this patch out? Again, I have no way to trigger that code, so I can't really test it. Pierre Muller as ARI maintainer. 2011-04-15 Pierre Muller ARI cleanup. * xtensa-tdep.c (xtensa_register_type): Use xstrprintf instead of sprintf. Simplify code and avoid loosing memory. (xtensa_register_reggroup_p): Extract assignment out of IF clause. (call0_frame_cache): Remove && operator from end of line. Index: xtensa-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/xtensa-tdep.c,v retrieving revision 1.57 diff -u -p -r1.57 xtensa-tdep.c --- xtensa-tdep.c 18 Mar 2011 18:52:32 -0000 1.57 +++ xtensa-tdep.c 15 Apr 2011 07:05:30 -0000 @@ -318,15 +318,14 @@ xtensa_register_type (struct gdbarch *gd if (tp == NULL) { - char *name = xmalloc (16); + char *name = xstrprintf ("int%d", size * 8); tp = xmalloc (sizeof (struct ctype_cache)); tp->next = tdep->type_entries; tdep->type_entries = tp; tp->size = size; - - sprintf (name, "int%d", size * 8); tp->virtual_type - = arch_integer_type (gdbarch, size * 8, 1, xstrdup (name)); + = arch_integer_type (gdbarch, size * 8, 1, name); + xfree (name); } reg->ctype = tp->virtual_type; @@ -843,7 +842,8 @@ xtensa_register_reggroup_p (struct gdbar if (group == restore_reggroup) return (regnum < gdbarch_num_regs (gdbarch) && (reg->flags & SAVE_REST_FLAGS) == SAVE_REST_VALID); - if ((cp_number = xtensa_coprocessor_register_group (group)) >= 0) + cp_number = xtensa_coprocessor_register_group (group); + if (cp_number >= 0) return rg & (xtRegisterGroupCP0 << cp_number); else return 1; @@ -2715,9 +2715,9 @@ call0_frame_cache (struct frame_info *th too bad. */ int i; - for (i = 0; - (i < C0_NREGS) && - (i == C0_RA || cache->c0.c0_rt[i].fr_reg != C0_RA); + for (i = 0; + (i < C0_NREGS) + && (i == C0_RA || cache->c0.c0_rt[i].fr_reg != C0_RA); ++i); if (i >= C0_NREGS && cache->c0.c0_rt[C0_RA].fr_reg == C0_RA) i = C0_RA;