You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
(58) |
Apr
(261) |
May
(169) |
Jun
(214) |
Jul
(201) |
Aug
(219) |
Sep
(198) |
Oct
(203) |
Nov
(241) |
Dec
(94) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(137) |
Feb
(149) |
Mar
(150) |
Apr
(193) |
May
(95) |
Jun
(173) |
Jul
(137) |
Aug
(236) |
Sep
(157) |
Oct
(150) |
Nov
(136) |
Dec
(90) |
| 2005 |
Jan
(139) |
Feb
(130) |
Mar
(274) |
Apr
(138) |
May
(184) |
Jun
(152) |
Jul
(261) |
Aug
(409) |
Sep
(239) |
Oct
(241) |
Nov
(260) |
Dec
(137) |
| 2006 |
Jan
(191) |
Feb
(142) |
Mar
(169) |
Apr
(75) |
May
(141) |
Jun
(169) |
Jul
(131) |
Aug
(141) |
Sep
(192) |
Oct
(176) |
Nov
(142) |
Dec
(95) |
| 2007 |
Jan
(98) |
Feb
(120) |
Mar
(93) |
Apr
(96) |
May
(95) |
Jun
(65) |
Jul
(62) |
Aug
(56) |
Sep
(53) |
Oct
(95) |
Nov
(106) |
Dec
(87) |
| 2008 |
Jan
(58) |
Feb
(149) |
Mar
(175) |
Apr
(110) |
May
(106) |
Jun
(72) |
Jul
(55) |
Aug
(89) |
Sep
(26) |
Oct
(96) |
Nov
(83) |
Dec
(93) |
| 2009 |
Jan
(97) |
Feb
(106) |
Mar
(74) |
Apr
(64) |
May
(115) |
Jun
(83) |
Jul
(137) |
Aug
(103) |
Sep
(56) |
Oct
(59) |
Nov
(61) |
Dec
(37) |
| 2010 |
Jan
(94) |
Feb
(71) |
Mar
(53) |
Apr
(105) |
May
(79) |
Jun
(111) |
Jul
(110) |
Aug
(81) |
Sep
(50) |
Oct
(82) |
Nov
(49) |
Dec
(21) |
| 2011 |
Jan
(87) |
Feb
(105) |
Mar
(108) |
Apr
(99) |
May
(91) |
Jun
(94) |
Jul
(114) |
Aug
(77) |
Sep
(58) |
Oct
(58) |
Nov
(131) |
Dec
(62) |
| 2012 |
Jan
(76) |
Feb
(93) |
Mar
(68) |
Apr
(95) |
May
(62) |
Jun
(109) |
Jul
(90) |
Aug
(87) |
Sep
(49) |
Oct
(54) |
Nov
(66) |
Dec
(84) |
| 2013 |
Jan
(67) |
Feb
(52) |
Mar
(93) |
Apr
(65) |
May
(33) |
Jun
(34) |
Jul
(52) |
Aug
(42) |
Sep
(52) |
Oct
(48) |
Nov
(66) |
Dec
(14) |
| 2014 |
Jan
(66) |
Feb
(51) |
Mar
(34) |
Apr
(47) |
May
(58) |
Jun
(27) |
Jul
(52) |
Aug
(41) |
Sep
(78) |
Oct
(30) |
Nov
(28) |
Dec
(26) |
| 2015 |
Jan
(41) |
Feb
(42) |
Mar
(20) |
Apr
(73) |
May
(31) |
Jun
(48) |
Jul
(23) |
Aug
(55) |
Sep
(36) |
Oct
(47) |
Nov
(48) |
Dec
(41) |
| 2016 |
Jan
(32) |
Feb
(34) |
Mar
(33) |
Apr
(22) |
May
(14) |
Jun
(31) |
Jul
(29) |
Aug
(41) |
Sep
(17) |
Oct
(27) |
Nov
(38) |
Dec
(28) |
| 2017 |
Jan
(28) |
Feb
(30) |
Mar
(16) |
Apr
(9) |
May
(27) |
Jun
(57) |
Jul
(28) |
Aug
(43) |
Sep
(31) |
Oct
(20) |
Nov
(24) |
Dec
(18) |
| 2018 |
Jan
(34) |
Feb
(50) |
Mar
(18) |
Apr
(26) |
May
(13) |
Jun
(31) |
Jul
(13) |
Aug
(11) |
Sep
(15) |
Oct
(12) |
Nov
(18) |
Dec
(13) |
| 2019 |
Jan
(12) |
Feb
(29) |
Mar
(51) |
Apr
(22) |
May
(13) |
Jun
(20) |
Jul
(13) |
Aug
(12) |
Sep
(21) |
Oct
(6) |
Nov
(9) |
Dec
(5) |
| 2020 |
Jan
(13) |
Feb
(5) |
Mar
(25) |
Apr
(4) |
May
(40) |
Jun
(27) |
Jul
(5) |
Aug
(17) |
Sep
(21) |
Oct
(1) |
Nov
(5) |
Dec
(15) |
| 2021 |
Jan
(28) |
Feb
(6) |
Mar
(11) |
Apr
(5) |
May
(7) |
Jun
(8) |
Jul
(5) |
Aug
(5) |
Sep
(11) |
Oct
(9) |
Nov
(10) |
Dec
(12) |
| 2022 |
Jan
(7) |
Feb
(13) |
Mar
(8) |
Apr
(7) |
May
(12) |
Jun
(27) |
Jul
(14) |
Aug
(27) |
Sep
(27) |
Oct
(17) |
Nov
(17) |
Dec
|
| 2023 |
Jan
(10) |
Feb
(18) |
Mar
(9) |
Apr
(26) |
May
|
Jun
(13) |
Jul
(18) |
Aug
(5) |
Sep
|
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
1
|
|
2
|
3
|
4
|
5
|
6
(5) |
7
(3) |
8
|
|
9
(3) |
10
(1) |
11
(2) |
12
(3) |
13
(9) |
14
(2) |
15
|
|
16
|
17
(4) |
18
(5) |
19
(1) |
20
|
21
(4) |
22
(1) |
|
23
(1) |
24
(1) |
25
(3) |
26
(2) |
27
|
28
(2) |
29
|
|
30
(1) |
|
|
|
|
|
|
|
From: Nicholas N. <nj...@cs...> - 2007-09-17 22:28:55
|
On Mon, 17 Sep 2007, Jim Cromie wrote: > obviously, less misses are better, but whats reasonable ? > > - what kind of numbers indicate "trouble" > ie performance impacts Your question prompted me to write a new section in the manual answering that question. I've attached it at the bottom of this message. > - is there a repo of results kept anywhere ? > obviously, programs have to be doing a defined, repeatable task No, but you've built up a nice repo yourself, so you can get a feel for the relative results. > - cachegrind assumes the whole L1,L2 cache are available > for use by a single application - Is it reasonable to "derate" > the cache to represent the workload of a typical/idle desktop box ? > > forex: > --cache-derate=10/10/10 Getting the details right so this would be meaningful would be difficult. I don't think you could easily encapsulate the effect of concurrent workloads just with a couple of numbers like that. If the machine is idle apart from the one program, the Cachegrind numbers are generally pretty close. This paper http://www.cs.mu.oz.au/~njn/pubs/cache-large-lazy2002.ps has some figures comparing Cachegrind results to hardware counter results, they weren't bad. Nick <sect1> <title>Acting on Cachegrind's information</title> <para> So, you've managed to profile your program with Cachegrind. Now what? What's the best way to actually act on the information it provides to speed up your program? Here are some rules of thumb that we have found to be useful.</para> <para> First of all, the global hit/miss rate numbers are not that useful. If you have multiple programs or multiple runs of a program, comparing the numbers might identify if any are outliers and worthy of closer investigation. Otherwise, they're not enough to act on.</para> <para> The line-by-line source code annotations are much more useful. In our experience, the best place to start is by looking at the <computeroutput>Ir</computeroutput> numbers. They simply measure how many instructions were executed for each line, and don't include any cache information, but they can still be very useful for identifying bottlenecks.</para> <para> After that, we have found that L2 misses are typically a much bigger source of slow-downs than L1 misses. So it's worth looking for any snippets of code that cause a high proportion of the L2 misses. If you find any, it's still not always easy to work out how to improve things. You need to have a reasonable understanding of how caches work, the principles of locality, and your program's data access patterns. Improving things may require redesigning a data structure, for example.</para> <para> In short, Cachegrind can tell you where some of the bottlenecks in your code are, but it can't tell you how to fix them. You have to work that out for yourself. But at least you have the information! </para> </sect1> |
|
From: Jim C. <jim...@gm...> - 2007-09-17 18:09:13
|
obviously, less misses are better, but whats reasonable ?
- what kind of numbers indicate "trouble"
ie performance impacts
- is there a repo of results kept anywhere ?
obviously, programs have to be doing a defined, repeatable task
- cachegrind assumes the whole L1,L2 cache are available
for use by a single application - Is it reasonable to "derate"
the cache to represent the workload of a typical/idle desktop box ?
forex:
--cache-derate=10/10/10
The Perl distribution has a make "test.valgrind" target
that can also be used to run cachegrind tests.
VG_OPTS=--tool=cachegrind make test.valgrind
Ive used it to generate a slew of results - one for each of the 1458
progs that comprise the regression test suite. I then wrote a perl script
to parse the data out of the reports, and compute avg and std-dev
for each subdirectory in the result set.
heres a randomly chosen chunk
vg-cache-test/lib: $VAR1 = {
'D1-mean' => '0.556603773584906',
'D1-stdev' => '0.19280397118969',
'I1-mean' => '1.38188679245283',
'I1-stdev' => '0.358503475437871',
'L2-mean' => '0.0113207547169811',
'L2-stdev' => '0.0419360580582884',
'L2d-mean' => '0.030188679245283',
'L2d-stdev' => '0.0766883072939682',
'L2i-mean' => '0.0224528301886793',
'L2i-stdev' => '0.0408820512527386'
};
vg-cache-test/t/uni: $VAR1 = {
'D1-mean' => '0.529411764705882',
'D1-stdev' => '0.152488016433126',
'I1-mean' => '1.39588235294118',
'I1-stdev' => '0.292093031584709',
'L2-mean' => '0',
'L2-stdev' => '0',
'L2d-mean' => '0.0352941176470588',
'L2d-stdev' => '0.0477884612037409',
'L2i-mean' => '0.00764705882352941',
'L2i-stdev' => '0.0111299340755438'
};
vg-cache-test/lib/Tie/Handle: $VAR1 = {
'D1-mean' => '0.45',
'D1-stdev' => '0.05',
'I1-mean' => '1.48',
'I1-stdev' => '0.03',
'L2-mean' => '0',
'L2-stdev' => '0',
'L2d-mean' => '0.05',
'L2d-stdev' => '0.05',
'L2i-mean' => '0.025',
'L2i-stdev' => '0.015'
};
Then, doing a simple:
$ grep D1 vg-sum-cache-test |sort
on the above output, I get:
[jimc@harpo vg-stuff]$ grep D1 vg-sum-cache-test |sort
'D1-mean' => '0',
'D1-mean' => '0.4',
'D1-mean' => '0.4',
'D1-mean' => '0.4',
'D1-mean' => '0.4',
'D1-mean' => '0.4',
'D1-mean' => '0.4',
'D1-mean' => '0.4',
'D1-mean' => '0.4125',
'D1-mean' => '0.416666666666667',
'D1-mean' => '0.42',
'D1-mean' => '0.425',
'D1-mean' => '0.428571428571428',
'D1-mean' => '0.428571428571429',
'D1-mean' => '0.43125',
'D1-mean' => '0.433333333333333',
'D1-mean' => '0.433333333333333',
'D1-mean' => '0.435',
'D1-mean' => '0.4375',
'D1-mean' => '0.442857142857143',
'D1-mean' => '0.45',
'D1-mean' => '0.45',
'D1-mean' => '0.45',
'D1-mean' => '0.45',
'D1-mean' => '0.45',
'D1-mean' => '0.466666666666667',
'D1-mean' => '0.466666666666667',
'D1-mean' => '0.471428571428571',
'D1-mean' => '0.483333333333333',
'D1-mean' => '0.484210526315789',
'D1-mean' => '0.490909090909091',
'D1-mean' => '0.492156862745098',
'D1-mean' => '0.495',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.5',
'D1-mean' => '0.503125',
'D1-mean' => '0.503703703703704',
'D1-mean' => '0.514285714285714',
'D1-mean' => '0.514285714285714',
'D1-mean' => '0.516666666666667',
'D1-mean' => '0.52',
'D1-mean' => '0.52',
'D1-mean' => '0.528571428571429',
'D1-mean' => '0.529411764705882',
'D1-mean' => '0.529411764705882',
'D1-mean' => '0.529411764705882',
'D1-mean' => '0.533333333333333',
'D1-mean' => '0.533333333333333',
'D1-mean' => '0.533333333333333',
'D1-mean' => '0.533333333333333',
'D1-mean' => '0.538888888888889',
'D1-mean' => '0.538888888888889',
'D1-mean' => '0.54',
'D1-mean' => '0.54',
'D1-mean' => '0.542857142857143',
'D1-mean' => '0.545098039215686',
'D1-mean' => '0.55',
'D1-mean' => '0.55',
'D1-mean' => '0.55',
'D1-mean' => '0.55',
'D1-mean' => '0.55',
'D1-mean' => '0.55',
'D1-mean' => '0.555555555555556',
'D1-mean' => '0.556603773584906',
'D1-mean' => '0.563031550068588',
'D1-mean' => '0.573913043478261',
'D1-mean' => '0.577777777777778',
'D1-mean' => '0.583333333333333',
'D1-mean' => '0.585714285714286',
'D1-mean' => '0.588461538461538',
'D1-mean' => '0.588888888888889',
'D1-mean' => '0.589473684210526',
'D1-mean' => '0.591666666666667',
'D1-mean' => '0.594444444444444',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6',
'D1-mean' => '0.6125',
'D1-mean' => '0.616666666666667',
'D1-mean' => '0.630434782608696',
'D1-mean' => '0.64',
'D1-mean' => '0.646666666666667',
'D1-mean' => '0.646875',
'D1-mean' => '0.65',
'D1-mean' => '0.686842105263158',
'D1-mean' => '0.7',
'D1-mean' => '0.7',
'D1-mean' => '0.7',
'D1-mean' => '0.7',
'D1-mean' => '0.714285714285714',
'D1-mean' => '0.722222222222222',
'D1-mean' => '0.759016393442623',
'D1-mean' => '0.8',
'D1-mean' => '0.8',
'D1-mean' => '0.8',
'D1-mean' => '0.8',
'D1-mean' => '0.838888888888889',
'D1-mean' => '0.846666666666667',
'D1-mean' => '0.95',
'D1-mean' => '0.95',
'D1-mean' => '1.35',
'D1-stdev' => '0',
<snip>
'D1-stdev' => '0',
'D1-stdev' => '0',
'D1-stdev' => '0.0287479787288034',
'D1-stdev' => '0.0319485533189157',
'D1-stdev' => '0.0330718913883074',
'D1-stdev' => '0.0372677996249965',
'D1-stdev' => '0.0372677996249965',
'D1-stdev' => '0.04',
'D1-stdev' => '0.04',
'D1-stdev' => '0.0433012701892219',
'D1-stdev' => '0.0451753951452626',
'D1-stdev' => '0.0463512405443479',
'D1-stdev' => '0.0471404520791032',
'D1-stdev' => '0.0471404520791032',
'D1-stdev' => '0.0471404520791032',
'D1-stdev' => '0.0471404520791032',
'D1-stdev' => '0.0471404520791032',
'D1-stdev' => '0.0471404520791032',
'D1-stdev' => '0.0494871659305393',
'D1-stdev' => '0.0496903994999953',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.05',
'D1-stdev' => '0.057227615711298',
'D1-stdev' => '0.063661089960823',
'D1-stdev' => '0.063887656499994',
'D1-stdev' => '0.0652089770522191',
'D1-stdev' => '0.0665512264646162',
'D1-stdev' => '0.0687184270936277',
'D1-stdev' => '0.0695970545353753',
'D1-stdev' => '0.0699854212223765',
'D1-stdev' => '0.0707106781186547',
'D1-stdev' => '0.0707106781186547',
'D1-stdev' => '0.0737027731190089',
'D1-stdev' => '0.0748701297726933',
'D1-stdev' => '0.0755637250485302',
'D1-stdev' => '0.0779759380423233',
'D1-stdev' => '0.08',
'D1-stdev' => '0.0816496580927726',
'D1-stdev' => '0.0816496580927726',
'D1-stdev' => '0.0816496580927726',
'D1-stdev' => '0.0816496580927726',
'D1-stdev' => '0.0816496580927726',
'D1-stdev' => '0.0816496580927726',
'D1-stdev' => '0.0864580823289529',
'D1-stdev' => '0.0866025403784439',
'D1-stdev' => '0.0897527467855751',
'D1-stdev' => '0.0916245694581702',
'D1-stdev' => '0.0916515138991168',
'D1-stdev' => '0.0925820099772552',
'D1-stdev' => '0.0989743318610787',
'D1-stdev' => '0.0989743318610787',
'D1-stdev' => '0.0999511599482467',
'D1-stdev' => '0.1',
'D1-stdev' => '0.1',
'D1-stdev' => '0.104978131833565',
'D1-stdev' => '0.105409255338946',
'D1-stdev' => '0.107690399861001',
'D1-stdev' => '0.111803398874989',
'D1-stdev' => '0.111879429756864',
'D1-stdev' => '0.122474487139159',
'D1-stdev' => '0.124721912892465',
'D1-stdev' => '0.128816217299269',
'D1-stdev' => '0.131909059582729',
'D1-stdev' => '0.14142135623731',
'D1-stdev' => '0.14239736061546',
'D1-stdev' => '0.146969384566991',
'D1-stdev' => '0.148718533708583',
'D1-stdev' => '0.15',
'D1-stdev' => '0.152488016433126',
'D1-stdev' => '0.166598625567009',
'D1-stdev' => '0.172614942479922',
'D1-stdev' => '0.173205080756888',
'D1-stdev' => '0.177169096878911',
'D1-stdev' => '0.182086670449969',
'D1-stdev' => '0.184554481530385',
'D1-stdev' => '0.188561808316413',
'D1-stdev' => '0.188970570574388',
'D1-stdev' => '0.191485421551268',
'D1-stdev' => '0.19280397118969',
'D1-stdev' => '0.2',
'D1-stdev' => '0.206155281280883',
'D1-stdev' => '0.213087839214658',
'D1-stdev' => '0.218671322200105',
'D1-stdev' => '0.231443828245418',
'D1-stdev' => '0.243938871112224',
'D1-stdev' => '0.280345768650073',
'D1-stdev' => '0.3',
'D1-stdev' => '0.319963346666265',
'D1-stdev' => '0.35',
'D1-stdev' => '0.36258536104526',
'D1-stdev' => '0.380992854992788',
'D1-stdev' => '0.3880932149501',
'D1-stdev' => '0.476969600708473',
'D1-stdev' => '1.53215534460446',
[jimc@harpo vg-stuff]$
Ive snipped some of the stddev results cuz the subset was 1 file
(so stddev is meaningless).
All of which brings me to my ROTR (rubber on the road) question(s):
What do these numbers mean ?
What else should the script do to extract meaning ?
Presuming I can make this script do enough good, Ill put it on CPAN.
tia
Jim Cromie
|
|
From: <led...@vt...> - 2007-09-17 17:41:26
|
I am lazy and didn't feel like analyzing the code, but I would suggest using the
--db-attach=yes flag and looking around the code in gdb where the error occurs.
Maybe you're going past a buffer and don't realize it because the code happens
to handle the situation.
-Cass
Quoting oma...@ju...:
> Hi everybody.
> I have some problems with a program using libexpat that parses a XML file,
> record s informations in an appropriate structure and finally prints this
> structure to stdout.
> The program is compiled with -Wall and -g flags and without optimization
> flag.
>
> -Here is the valgrind command line and output:
>
> valgrind --leak-check=yes --show-reachable=yes ./Parser miniprova.xml
>
>
> ==9608== Memcheck, a memory error detector.
> ==9608== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
> ==9608== Using LibVEX rev 1732, a library for dynamic binary translation.
> ==9608== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
> ==9608== Using valgrind-3.2.3, a dynamic binary instrumentation framework.
> ==9608== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
> ==9608== For more details, rerun with: -v
> ==9608==
> ==9608== Invalid read of size 1
> ==9608== at 0x4062474: elementContent (parserXMLquestions.c:434)
> ==9608== by 0x40490EE: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x404A15C: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x404B1FA: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x404C0C4: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x40437AB: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x40458A4: XML_Parse (in /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x4062AB1: parserXMLquestions (parserXMLquestions.c:599)
> ==9608== by 0x804867B: main (parserXMLquestions_test.c:19)
> ==9608== Address 0x419421B is 0 bytes after a block of size 11 alloc'd
> ==9608== at 0x4021888: malloc (in
> /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
> ==9608== by 0x406233A: elementContent (parserXMLquestions.c:398)
> ==9608== by 0x40490EE: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x404A15C: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x404B1FA: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x404C0C4: (within /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x40437AB: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x40458A4: XML_Parse (in /usr/lib/libexpat.so.1.5.2)
> ==9608== by 0x4062AB1: parserXMLquestions (parserXMLquestions.c:599)
> ==9608== by 0x804867B: main (parserXMLquestions_test.c:19)
>
> (a lot of errors like this...)
>
> ==9608== ERROR SUMMARY: 722 errors from 21 contexts (suppressed: 7 from 1)
> ==9608== malloc/free: in use at exit: 0 bytes in 0 blocks.
> ==9608== malloc/free: 76 allocs, 76 frees, 8,831 bytes allocated.
> ==9608== For counts of detected errors, rerun with: -v
> ==9608== All heap blocks were freed -- no leaks are possible.
>
>
> -Here is the source code:
>
> "ParserXMLquestions.c"
>
> 30 static int error = 0;
> 31
> 32 typedef enum element {
> 33 MultimediaElements, barcode, summary, MultimediaElement, ID,
> 34 Description, URI, Title, Video, width, height, fps, duration,
> 35 format, Audio, sampleFrequency, framerate, Image, Text, html,
> 36 ERRORTYPE = -1
> 37 } element_t;
> 38
> 39 typedef struct {
> 40 multimedia_elements_t *mets;
> 41 element_t trace_element;
> 42 } userData_t;
> ...
> 53 static inline element_t get_and_set_TypeElement (
> 54 const char *name,
> 55 element_t *setTrace ) {
> 56
> 57 int n;
> 64 n = strlen(name);
> 65 if (strncmp(name, "ID", n) == 0) {
> 66 *setTrace = ID;
> 67 return ID;
> 68 }
> 69 if (strncmp(name, "fps", n) == 0) {
> 70 *setTrace = fps;
> 71 return fps;
> 72 }
> 73 if (strncmp(name, "URI", n) == 0) {
> 74 *setTrace = URI;
> 75 return URI;
> 76 }
> 77 if (strncmp(name, "html", n) == 0) {
> 78 *setTrace = html;
> 79 return html;
> 80 }
> 81 if (strncmp(name, "Text", n) == 0) {
> 82 *setTrace = Text;
> 83 return Text;
> 84 }
> 85 if (strncmp(name, "Title", n) == 0) {
>
> (continues...)
> ...
> 316 static void XMLCALL startElement ( void *data,
> 317 const char *name, const char **attrs ) {
> 318
> 319 element_t type;
> 320 userData_t *udt = (userData_t *)data;
> 321
> 322 if (error != 0) return;
> 323
> 324 /** try to add a string variable containing "name" **/
> 325
> 326 type = get_and_set_TypeElement(name, &udt->trace_element) ;
> 327
> 328 switch (type) {
> 329 case MultimediaElement:
> 330 error = addMelement(udt->mets);
> 331 break;
> 332 case MultimediaElements:
> 333 /* must be the top-level container, so it must be empty when
> starting */
> 334 /** commmented for now
> 335 if (udt->mets->first_multimedia_element != NULL) {
> 336 error = -1;
> 337 break;
> 338 }
> 339 */
> 340 udt->mets->first_multimedia_element = NULL;
> 341 udt->mets->last_multimedia_element = NULL;
> 342 break;
> 343 case Video:
> 344 error = addVelement(udt->mets->last_multimedia_element);
> 345 break;
> 346 case Audio:
> 347 error = addAelement(udt->mets->last_multimedia_element);
> 348 break;
> 349 case Image:
> 350 error = addIelement(udt->mets->last_multimedia_element);
> 351 break;
> 352 case Text:
> 353 error = addTelement(udt->mets->last_multimedia_element);
> 354 break;
> 355 case barcode: case summary:
> 356 case ID: case Description:
> 357 case URI: case Title:
> 358 case width: case height:
> 359 case fps: case duration:
> 360 case format: case sampleFrequency:
> 361 case framerate: case html:
> 362 break;
> 363 case ERRORTYPE:
> 364 if (DEBUG)
> 365 fprintf(stderr, "Error: wrong element type\n");
> 366 error = 1;
> 367 break;
> 368 default:
> 369 break;
> 370 }
> 371 }
> ...
> void elementContent ( void *data,
> 384 const char *cont, int contlen ) {
> 385
> 386 userData_t *udt = (userData_t *)data;
> 387 char *source, *dest;
> 388 int n;
> 389 int num = contlen;
> 390
> 391 if (error) return;
> 392
> 393 source = dest = NULL;
> 394 n = 0;
> 395
> 396 n = contlen+1;
> 397 source = (char *)malloc(n);
> 398 dest = (char *)malloc(n);
> 399 if (source == NULL) {
> 400 free(dest);
> 401 if (DEBUG) fprintf(stderr, "Error: malloc\n");
> 402 error = 3;
> 403 return;
> 404 }
> 405 if (dest == NULL) {
> 406 free(source);
> 407 if (DEBUG) fprintf(stderr, "Error: malloc\n");
> 408 error = 3;
> 409 return;
> 410 }
> 411 memset(source, 0, n);
> 412 memset(dest, 0, n);
> 414 memcpy (source, cont, contlen);
> 415
> 416 multimedia_element_t *last =
> 417 udt->mets->last_multimedia_element;
> 427 if ( (strntrim(source, dest, contlen)) ||
> 428 (strlen (dest) <= 0) )
> 429 goto error;
> 430
> 431 /* Copies the content in the appropriate position */
> 432 switch (udt->trace_element) {
> 433 case barcode:
> 434 memcpy(udt->mets->barcode, dest, MAXBARCODELEN);
> 435 break;
> 436 case summary:
> 437 memcpy(udt->mets->summary, dest, MAXSTRINGLEN);
> 438 break;
> 439 case ID:
> 440 last->ID = (unsigned int)strtoul(dest, NULL, 10);
> 441 break;
> 442 case Description:
> 443 memcpy(last->Description, dest, MAXSTRINGLEN);
> 444 break;
> 445 case URI:
> 446 memcpy(last->URI, dest, MAXURILEN);
> 447 break;
> 448 case Title:
> 449 memcpy(last->Title, dest, MAXSTRINGLEN);
> 450 break;
> 451 case width:
> 452 if (last->video != NULL)
> 453 last->video->width = (unsigned int)
> 454 strtoul(dest, NULL, 10);
> 455 if (last->image != NULL)
> 456 last->image->width = (unsigned int)
> 457 strtoul(dest, NULL, 10);
> 458 break;
> 459 case height:
> 460 if (last->video != NULL)
> 461 last->video->height = (unsigned int)
> 462 strtoul(dest, NULL, 10);
> 463 if (last->image != NULL)
> 464 last->image->height = (unsigned int)
> 465 strtoul(dest, NULL, 10);
> 466 break;
> 467 case fps:
> 468 last->video->fps = (unsigned int)
> 469 strtoul(dest, NULL, 10);
> 470 break;
> 471 case duration:
> 472 if (last->video != NULL)
> 473 last->video->duration = (unsigned long int)
> 474 strtoul(dest, NULL, 10);
> 475 if (last->audio != NULL)
> 476 last->audio->duration = (unsigned long int)
> 477 strtoul(dest, NULL, 10);
> 478 break;
> 479 case format:
> 480 if (last->video != NULL)
> 481 memcpy(last->video->format, dest, MAXSTRINGLEN);
> 482 if (last->audio != NULL)
> 483 memcpy(last->audio->format, dest, MAXSTRINGLEN);
> 484 if (last->image != NULL)
> 485 memcpy(last->image->format, dest, MAXSTRINGLEN);
> 486 break;
> 487 case sampleFrequency:
> 488 last->audio->sample_frequency = strtof(dest, NULL);
> 489 break;
> 490 case framerate:
> 491 last->audio->framerate = (unsigned int)
> 492 strtoul(dest, NULL, 10);
> 493 break;
> 494 case html:
> 495 memcpy(last->html->html, dest, MAXURILEN);
> 496 break;
> 497 case ERRORTYPE:
> 498 if(DEBUG)
> 499 fprintf(stderr, "Error: wrong element type\n");
> 500 error = 1;
> 501 goto error;
> 502 break;
> 503 case MultimediaElement: case MultimediaElements:
> 504 case Image: case Text: case Video: case Audio:
> 505 break;
> 506 default:
> 507 break;
> 508 } /* end of switch */
> 515
> 517 error:
> 518 if (source != NULL)
> 519 free(source);
> 520 if (dest != NULL)
> 521 free(dest);
> 522 }
> ...
> 539 int parserXMLquestions ( char *path,
> 540 multimedia_elements_t *met ) {
> 541
> 542 FILE *fdXML = NULL;
> 543 int done = 0;
> 544 int len = 0;
> 545 char buff[BUFFSIZE];
> 546 userData_t udt;
> 547 int ret_val = -1;
> 548
> 549 if (path == NULL || met == NULL)
> 550 return 10;
> 551
> 553 if ((fdXML = fopen(path, "r")) == NULL) {
> 554 if (DEBUG)
> 555 fprintf(stderr, "Error. Couldn't open file\n");
> 556 return 2;
> 557 //ret_val = 2;
> 558 //goto horror;
> 559 }
> 560 // create parser
> 561 XML_Parser p = XML_ParserCreate(NULL);
> 562 if (! p) {
> 563 if (DEBUG)
> 564 fprintf(stderr, "Couldn't allocate"
> 565 "memory for parser\n");
> 566 free(fdXML);
> 567 return 3;
> 568 //ret_val = 3;
> 569 //goto horror;
> 570 }
> 571
> 573 udt.mets = met;
> 575 XML_SetUserData(p, &udt);
> 576
> 578 if ( XML_SetEncoding(p, ISO_8859_1) == XML_STATUS_ERROR ) {
> 579 if (DEBUG)
> 580 fprintf(stderr,
> 581 "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n",
> 582 (long unsigned int)XML_GetCurrentLineNumber(p),
> 583 XML_ErrorString(XML_GetErrorCode(p)));
> 584 ret_val = 9;
> 585 goto horror;
> 586 }
> 587 XML_SetElementHandler(p, startElement, NULL);
> 588 XML_SetCharacterDataHandler(p, elementContent);
> 589 // start parsing
> 590 do {
> 591 memset(buff, 0, BUFFSIZE);
> 592 len = (int)fread(buff, 1, BUFFSIZE, fdXML);
> 593 if (ferror(fdXML)) {
> 594 if (DEBUG) fprintf(stderr, "Read error\n");
> 595 ret_val = 4;
> 596 goto horror;
> 597 }
> 598 done = feof(fdXML);
> 599 if (XML_Parse(p, buff, len, done) == XML_STATUS_ERROR) {
> 600 if (DEBUG)
> 601 fprintf(stderr,
> 602 "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n",
> 603 (long unsigned int)XML_GetCurrentLineNumber(p),
> 604 XML_ErrorString(XML_GetErrorCode(p)));
> 605 ret_val = 5;
> 606 goto horror;
> 607 }
> 608 } while(!done);
> 609
> 610 if (error != 0) {
> 611 ret_val = error;
> 612 goto horror;
> 613 }
> 614
> 615 if (DEBUG)
> 616 showQuestionsTree (udt.mets);
> 617
> 619 XML_ParserFree(p);
> 620 fclose (fdXML);
> 621
> 622 return 0;
> 623
> 624 horror:
> 633 XML_ParserFree(p);
> 634 free(fdXML);
> 635
> 636 return ret_val;
> 637 }
> ...
> 647 void freeXMLquestions ( multimedia_elements_t *mets ) {
> 648
> 649 multimedia_element_t *tmp = NULL;
> 650 multimedia_element_t *first = NULL;
> 651
> 652 if (mets == NULL) return;
> 653
> 654 mets->last_multimedia_element = NULL;
> 655
> 656 if (mets->first_multimedia_element != NULL) {
> 657 first = mets->first_multimedia_element;
> 658 }
> 659 //while (mets->first_multimedia_element != NULL) {
> 660 while (first != NULL) {
> 661 tmp = first->next_multimedia_element;
> 662 if (first->video != NULL) {
> 663 free(first->video);
> 664 }
> 665 if (first->audio != NULL) {
> 666 free(first->audio);
> 667 }
> 668 if (first->image != NULL) {
> 669 free(first->image);
> 670 }
> 671 if (first->html != NULL) {
> 672 free(first->html);
> 673 }
> 674
> 675 free(first);
> 676 first = tmp;
> 677 }
> 678 free (mets);
> 679 }
>
>
> "prova2.xml"
>
> 1 <?xml version="1.0" encoding="ISO-8859-1" ?>
> 2
> 3 <MultimediaElements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="prova2.xsd" >
> 4
> 5 <barcode>123456789012345678901234567</barcode><summary>This barcode
> contains
> some interesting elements</summary><MultimediaElement><ID>1</ID
> ><Description>this is a
> description</Description><URI>http://www.jusan.it</URI><Title>title of
> element</Title><Video><width>576</width><heig
>
ht>320</height><fps>25</fps><duration>56000</duration><format>divx</format></Video></MultimediaElement><MultimediaElement><ID>1</ID><Descrip
> tion>this is a
> description</Description><URI>http://www.jusan.it</URI><Title>title of
> element</Title><Image><width>1024</width><height>768</
>
height><format>png</format></Image></MultimediaElement><MultimediaElement><ID>1</ID><Description>this
> is a description</Description><URI>htt p://www.jusan.it</URI><Title>title
> of
>
element</Title><Audio><duration>400</duration><sampleFrequency>44.1</sampleFrequency><framerate>192</f
>
>
ramerate><format>mp3-CBR</format></Audio></MultimediaElement><MultimediaElement><ID>1</ID><Description>this
> is a description</Description><U RI>http://www.jusan.it</URI><Title>title
> of
>
element</Title><Text><html>www.gazzetta.it</html></Text></MultimediaElement></MultimediaElements
> >
>
> The program runs, but I can't eliminate the above messages.
> Do anyone have some suggestions? Thanks in advance.
>
> Omar
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
|
|
From: <oma...@ju...> - 2007-09-17 16:33:06
|
Hi everybody.
I have some problems with a program using libexpat that parses a XML file,
record s informations in an appropriate structure and finally prints this
structure to stdout.
The program is compiled with -Wall and -g flags and without optimization flag.
-Here is the valgrind command line and output:
valgrind --leak-check=yes --show-reachable=yes ./Parser miniprova.xml
==9608== Memcheck, a memory error detector.
==9608== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==9608== Using LibVEX rev 1732, a library for dynamic binary translation.
==9608== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==9608== Using valgrind-3.2.3, a dynamic binary instrumentation framework.
==9608== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==9608== For more details, rerun with: -v
==9608==
==9608== Invalid read of size 1
==9608== at 0x4062474: elementContent (parserXMLquestions.c:434)
==9608== by 0x40490EE: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x404A15C: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x404B1FA: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x404C0C4: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x40437AB: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.2)
==9608== by 0x40458A4: XML_Parse (in /usr/lib/libexpat.so.1.5.2)
==9608== by 0x4062AB1: parserXMLquestions (parserXMLquestions.c:599)
==9608== by 0x804867B: main (parserXMLquestions_test.c:19)
==9608== Address 0x419421B is 0 bytes after a block of size 11 alloc'd
==9608== at 0x4021888: malloc (in
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==9608== by 0x406233A: elementContent (parserXMLquestions.c:398)
==9608== by 0x40490EE: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x404A15C: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x404B1FA: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x404C0C4: (within /usr/lib/libexpat.so.1.5.2)
==9608== by 0x40437AB: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.2)
==9608== by 0x40458A4: XML_Parse (in /usr/lib/libexpat.so.1.5.2)
==9608== by 0x4062AB1: parserXMLquestions (parserXMLquestions.c:599)
==9608== by 0x804867B: main (parserXMLquestions_test.c:19)
(a lot of errors like this...)
==9608== ERROR SUMMARY: 722 errors from 21 contexts (suppressed: 7 from 1)
==9608== malloc/free: in use at exit: 0 bytes in 0 blocks.
==9608== malloc/free: 76 allocs, 76 frees, 8,831 bytes allocated.
==9608== For counts of detected errors, rerun with: -v
==9608== All heap blocks were freed -- no leaks are possible.
-Here is the source code:
"ParserXMLquestions.c"
30 static int error = 0;
31
32 typedef enum element {
33 MultimediaElements, barcode, summary, MultimediaElement, ID,
34 Description, URI, Title, Video, width, height, fps, duration,
35 format, Audio, sampleFrequency, framerate, Image, Text, html,
36 ERRORTYPE = -1
37 } element_t;
38
39 typedef struct {
40 multimedia_elements_t *mets;
41 element_t trace_element;
42 } userData_t;
...
53 static inline element_t get_and_set_TypeElement (
54 const char *name,
55 element_t *setTrace ) {
56
57 int n;
64 n = strlen(name);
65 if (strncmp(name, "ID", n) == 0) {
66 *setTrace = ID;
67 return ID;
68 }
69 if (strncmp(name, "fps", n) == 0) {
70 *setTrace = fps;
71 return fps;
72 }
73 if (strncmp(name, "URI", n) == 0) {
74 *setTrace = URI;
75 return URI;
76 }
77 if (strncmp(name, "html", n) == 0) {
78 *setTrace = html;
79 return html;
80 }
81 if (strncmp(name, "Text", n) == 0) {
82 *setTrace = Text;
83 return Text;
84 }
85 if (strncmp(name, "Title", n) == 0) {
(continues...)
...
316 static void XMLCALL startElement ( void *data,
317 const char *name, const char **attrs ) {
318
319 element_t type;
320 userData_t *udt = (userData_t *)data;
321
322 if (error != 0) return;
323
324 /** try to add a string variable containing "name" **/
325
326 type = get_and_set_TypeElement(name, &udt->trace_element) ;
327
328 switch (type) {
329 case MultimediaElement:
330 error = addMelement(udt->mets);
331 break;
332 case MultimediaElements:
333 /* must be the top-level container, so it must be empty when
starting */
334 /** commmented for now
335 if (udt->mets->first_multimedia_element != NULL) {
336 error = -1;
337 break;
338 }
339 */
340 udt->mets->first_multimedia_element = NULL;
341 udt->mets->last_multimedia_element = NULL;
342 break;
343 case Video:
344 error = addVelement(udt->mets->last_multimedia_element);
345 break;
346 case Audio:
347 error = addAelement(udt->mets->last_multimedia_element);
348 break;
349 case Image:
350 error = addIelement(udt->mets->last_multimedia_element);
351 break;
352 case Text:
353 error = addTelement(udt->mets->last_multimedia_element);
354 break;
355 case barcode: case summary:
356 case ID: case Description:
357 case URI: case Title:
358 case width: case height:
359 case fps: case duration:
360 case format: case sampleFrequency:
361 case framerate: case html:
362 break;
363 case ERRORTYPE:
364 if (DEBUG)
365 fprintf(stderr, "Error: wrong element type\n");
366 error = 1;
367 break;
368 default:
369 break;
370 }
371 }
...
void elementContent ( void *data,
384 const char *cont, int contlen ) {
385
386 userData_t *udt = (userData_t *)data;
387 char *source, *dest;
388 int n;
389 int num = contlen;
390
391 if (error) return;
392
393 source = dest = NULL;
394 n = 0;
395
396 n = contlen+1;
397 source = (char *)malloc(n);
398 dest = (char *)malloc(n);
399 if (source == NULL) {
400 free(dest);
401 if (DEBUG) fprintf(stderr, "Error: malloc\n");
402 error = 3;
403 return;
404 }
405 if (dest == NULL) {
406 free(source);
407 if (DEBUG) fprintf(stderr, "Error: malloc\n");
408 error = 3;
409 return;
410 }
411 memset(source, 0, n);
412 memset(dest, 0, n);
414 memcpy (source, cont, contlen);
415
416 multimedia_element_t *last =
417 udt->mets->last_multimedia_element;
427 if ( (strntrim(source, dest, contlen)) ||
428 (strlen (dest) <= 0) )
429 goto error;
430
431 /* Copies the content in the appropriate position */
432 switch (udt->trace_element) {
433 case barcode:
434 memcpy(udt->mets->barcode, dest, MAXBARCODELEN);
435 break;
436 case summary:
437 memcpy(udt->mets->summary, dest, MAXSTRINGLEN);
438 break;
439 case ID:
440 last->ID = (unsigned int)strtoul(dest, NULL, 10);
441 break;
442 case Description:
443 memcpy(last->Description, dest, MAXSTRINGLEN);
444 break;
445 case URI:
446 memcpy(last->URI, dest, MAXURILEN);
447 break;
448 case Title:
449 memcpy(last->Title, dest, MAXSTRINGLEN);
450 break;
451 case width:
452 if (last->video != NULL)
453 last->video->width = (unsigned int)
454 strtoul(dest, NULL, 10);
455 if (last->image != NULL)
456 last->image->width = (unsigned int)
457 strtoul(dest, NULL, 10);
458 break;
459 case height:
460 if (last->video != NULL)
461 last->video->height = (unsigned int)
462 strtoul(dest, NULL, 10);
463 if (last->image != NULL)
464 last->image->height = (unsigned int)
465 strtoul(dest, NULL, 10);
466 break;
467 case fps:
468 last->video->fps = (unsigned int)
469 strtoul(dest, NULL, 10);
470 break;
471 case duration:
472 if (last->video != NULL)
473 last->video->duration = (unsigned long int)
474 strtoul(dest, NULL, 10);
475 if (last->audio != NULL)
476 last->audio->duration = (unsigned long int)
477 strtoul(dest, NULL, 10);
478 break;
479 case format:
480 if (last->video != NULL)
481 memcpy(last->video->format, dest, MAXSTRINGLEN);
482 if (last->audio != NULL)
483 memcpy(last->audio->format, dest, MAXSTRINGLEN);
484 if (last->image != NULL)
485 memcpy(last->image->format, dest, MAXSTRINGLEN);
486 break;
487 case sampleFrequency:
488 last->audio->sample_frequency = strtof(dest, NULL);
489 break;
490 case framerate:
491 last->audio->framerate = (unsigned int)
492 strtoul(dest, NULL, 10);
493 break;
494 case html:
495 memcpy(last->html->html, dest, MAXURILEN);
496 break;
497 case ERRORTYPE:
498 if(DEBUG)
499 fprintf(stderr, "Error: wrong element type\n");
500 error = 1;
501 goto error;
502 break;
503 case MultimediaElement: case MultimediaElements:
504 case Image: case Text: case Video: case Audio:
505 break;
506 default:
507 break;
508 } /* end of switch */
515
517 error:
518 if (source != NULL)
519 free(source);
520 if (dest != NULL)
521 free(dest);
522 }
...
539 int parserXMLquestions ( char *path,
540 multimedia_elements_t *met ) {
541
542 FILE *fdXML = NULL;
543 int done = 0;
544 int len = 0;
545 char buff[BUFFSIZE];
546 userData_t udt;
547 int ret_val = -1;
548
549 if (path == NULL || met == NULL)
550 return 10;
551
553 if ((fdXML = fopen(path, "r")) == NULL) {
554 if (DEBUG)
555 fprintf(stderr, "Error. Couldn't open file\n");
556 return 2;
557 //ret_val = 2;
558 //goto horror;
559 }
560 // create parser
561 XML_Parser p = XML_ParserCreate(NULL);
562 if (! p) {
563 if (DEBUG)
564 fprintf(stderr, "Couldn't allocate"
565 "memory for parser\n");
566 free(fdXML);
567 return 3;
568 //ret_val = 3;
569 //goto horror;
570 }
571
573 udt.mets = met;
575 XML_SetUserData(p, &udt);
576
578 if ( XML_SetEncoding(p, ISO_8859_1) == XML_STATUS_ERROR ) {
579 if (DEBUG)
580 fprintf(stderr,
581 "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n",
582 (long unsigned int)XML_GetCurrentLineNumber(p),
583 XML_ErrorString(XML_GetErrorCode(p)));
584 ret_val = 9;
585 goto horror;
586 }
587 XML_SetElementHandler(p, startElement, NULL);
588 XML_SetCharacterDataHandler(p, elementContent);
589 // start parsing
590 do {
591 memset(buff, 0, BUFFSIZE);
592 len = (int)fread(buff, 1, BUFFSIZE, fdXML);
593 if (ferror(fdXML)) {
594 if (DEBUG) fprintf(stderr, "Read error\n");
595 ret_val = 4;
596 goto horror;
597 }
598 done = feof(fdXML);
599 if (XML_Parse(p, buff, len, done) == XML_STATUS_ERROR) {
600 if (DEBUG)
601 fprintf(stderr,
602 "Parse error at line %" XML_FMT_INT_MOD "u:\n%s\n",
603 (long unsigned int)XML_GetCurrentLineNumber(p),
604 XML_ErrorString(XML_GetErrorCode(p)));
605 ret_val = 5;
606 goto horror;
607 }
608 } while(!done);
609
610 if (error != 0) {
611 ret_val = error;
612 goto horror;
613 }
614
615 if (DEBUG)
616 showQuestionsTree (udt.mets);
617
619 XML_ParserFree(p);
620 fclose (fdXML);
621
622 return 0;
623
624 horror:
633 XML_ParserFree(p);
634 free(fdXML);
635
636 return ret_val;
637 }
...
647 void freeXMLquestions ( multimedia_elements_t *mets ) {
648
649 multimedia_element_t *tmp = NULL;
650 multimedia_element_t *first = NULL;
651
652 if (mets == NULL) return;
653
654 mets->last_multimedia_element = NULL;
655
656 if (mets->first_multimedia_element != NULL) {
657 first = mets->first_multimedia_element;
658 }
659 //while (mets->first_multimedia_element != NULL) {
660 while (first != NULL) {
661 tmp = first->next_multimedia_element;
662 if (first->video != NULL) {
663 free(first->video);
664 }
665 if (first->audio != NULL) {
666 free(first->audio);
667 }
668 if (first->image != NULL) {
669 free(first->image);
670 }
671 if (first->html != NULL) {
672 free(first->html);
673 }
674
675 free(first);
676 first = tmp;
677 }
678 free (mets);
679 }
"prova2.xml"
1 <?xml version="1.0" encoding="ISO-8859-1" ?>
2
3 <MultimediaElements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="prova2.xsd" >
4
5 <barcode>123456789012345678901234567</barcode><summary>This barcode contains
some interesting elements</summary><MultimediaElement><ID>1</ID
><Description>this is a
description</Description><URI>http://www.jusan.it</URI><Title>title of
element</Title><Video><width>576</width><heig
ht>320</height><fps>25</fps><duration>56000</duration><format>divx</format></Video></MultimediaElement><MultimediaElement><ID>1</ID><Descrip
tion>this is a
description</Description><URI>http://www.jusan.it</URI><Title>title of
element</Title><Image><width>1024</width><height>768</
height><format>png</format></Image></MultimediaElement><MultimediaElement><ID>1</ID><Description>this
is a description</Description><URI>htt p://www.jusan.it</URI><Title>title of
element</Title><Audio><duration>400</duration><sampleFrequency>44.1</sampleFrequency><framerate>192</f
ramerate><format>mp3-CBR</format></Audio></MultimediaElement><MultimediaElement><ID>1</ID><Description>this
is a description</Description><U RI>http://www.jusan.it</URI><Title>title of
element</Title><Text><html>www.gazzetta.it</html></Text></MultimediaElement></MultimediaElements
>
The program runs, but I can't eliminate the above messages.
Do anyone have some suggestions? Thanks in advance.
Omar
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
|