[PATCH] tests: plug long-standing leak in test-only parsing code

Jim Meyering jim at meyering.net
Wed Mar 23 17:36:32 UTC 2011


FYI, testing with valgrind exposed this tiny leak:

  ==10098== 2 bytes in 1 blocks are definitely lost in loss record 1 of 1
  ==10098==    at 0x4A05E46: malloc (vg_replace_malloc.c:195)
  ==10098==    by 0x405D18: xmalloc (xmalloc.c:43)
  ==10098==    by 0x405E1F: xmemdup (xmalloc.c:107)
  ==10098==    by 0x405E5F: xstrdup (xmalloc.c:115)
  ==10098==    by 0x402E91: unit_oget_func (qparser.y:278)
  ==10098==    by 0x40304B: _print_value (qparser.y:343)
  ==10098==    by 0x403224: _print_value (qparser.y:378)
  ==10098==    by 0x403224: _print_value (qparser.y:378)
  ==10098==    by 0x4030F8: _print_value (qparser.y:359)
  ==10098==    by 0x403149: _print_value (qparser.y:364)
  ==10098==    by 0x40319A: _print_value (qparser.y:369)
  ==10098==    by 0x40329B: print_value (qparser.y:390)
  ==10098==    by 0x405BDC: main (qparser.y:627)

It didn't really matter, since it was in test-only code,
but eliminating it does it easier to spot real ones.

>From 5e22c670786c5e8b6c03e3f160b892c23bd3a124 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 23 Mar 2011 18:34:03 +0100
Subject: [PATCH] tests: plug long-standing leak in test-only parsing code

* qparser.y [PARSER_UNIT_TEST] (unit_oget_func): Don't xstrdup
the returned value.
---
 qparser.y |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/qparser.y b/qparser.y
index b6efb83..dbc6ce4 100644
--- a/qparser.y
+++ b/qparser.y
@@ -275,7 +275,7 @@ unit_oget_func (void * notused, const char *text)

 	for (i = 0; hacked_obj_fields[i].name; ++i) {
 		if (!strcmp(hacked_obj_fields[i].name,text)) {
-			return xstrdup(hacked_obj_fields[i].value);
+			return hacked_obj_fields[i].value;
 		}
 	}

--
1.7.4.1.586.g18336


More information about the iwhd-devel mailing list