Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

41

18.11.2009, 18:09

hast eigentlich schon mal valgrind drüber laufen lassen, kompiliers mir -g a pluto und lass dann valgrind mit -v --tool=memcheck drüber... dann gibts dir wirklich sehr genau an was mit deinem pointer passiert und wann und wo der fehler sein könnt... -g beim kompilieren is wichtig damitst die zeilen bekommst die falsch sind. hab letze woche stundenlang debugt und wäre ohne valgrind net draufkommen...


und ja ... wird wohl immer ein mysterium bleiben wer i bin.. gg..


lg

$nooc

Alter Hase

  • »$nooc« ist der Autor dieses Themas

Beiträge: 873

Wohnort: Österreich / Kärnten

Beruf: Schüler

  • Private Nachricht senden

42

18.11.2009, 21:12

ja habs mit valgrind auch schon versucht, aber da kommen ein paar andere lustige errors..

da getchar() am ende der main is nur da damit meine console offen bleibt wenn ichs auf meinem laptop compiliere. das getchar() in getInput() brauch ich damit ich dann im gcc einfach ./myprog < input.txt schreiben kann..

kann sich evtl. jemand die funktion
getInput() bzw. shiftString() mal durchlesen und mir sagen ob ich da nicht vllt. irgendwas falsch mache.. ich komme einfach nicht selbst dahinter. :(

ich poste hier mal was mir gcc schreibt, mir sagt das einfach nix ^^

Edit:
bei LEAK SUMMARY steht darunter:
==10954== definitely lost: 3,424 bytes in 28 blocks.

diese bytes sind wegen dem compiler selbst verloren, nicht wegen meines programmes.. also daran liegts nicht falls jemand damit argumentieren will..


Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes  gcc -Wall -o exx exx.c



 exx.c:150: error: redefinition of âlenstrâ
exx.c:140: error: previous definition of âlenstrâ was here
exx.c:161: error: redefinition of âmainâ
exx.c:14: error: previous definition of âmainâ was here
==13165==
==13165== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 1)
--13165--
--13165-- supp:   12 Fedora-Core-6-hack3-ld25
==13165== malloc/free: in use at exit: 18,448 bytes in 70 blocks.
==13165== malloc/free: 209 allocs, 139 frees, 28,785 bytes allocated.
==13165==
==13165== searching for pointers to 70 not-freed blocks.
==13165== checked 54,332 bytes.
==13165==
==13165== 1 bytes in 1 blocks are definitely lost in loss record 1 of 6
==13165==    at 0x40046FF: calloc (vg_replace_malloc.c:279)
==13165==    by 0x806082B: (within /usr/bin/gcc)
==13165==    by 0x8053EB4: (within /usr/bin/gcc)
==13165==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13165==
==13165==
==13165== 16 bytes in 1 blocks are indirectly lost in loss record 2 of 6
==13165==    at 0x40053C0: malloc (vg_replace_malloc.c:149)
==13165==    by 0x8060877: (within /usr/bin/gcc)
==13165==    by 0x80608F1: (within /usr/bin/gcc)
==13165==    by 0x8049572: (within /usr/bin/gcc)
==13165==    by 0x804B086: (within /usr/bin/gcc)
==13165==    by 0x8050266: (within /usr/bin/gcc)
==13165==    by 0x8052791: (within /usr/bin/gcc)
==13165==    by 0x80501C6: (within /usr/bin/gcc)
==13165==    by 0x8050313: (within /usr/bin/gcc)
==13165==    by 0x8052791: (within /usr/bin/gcc)
==13165==    by 0x80501C6: (within /usr/bin/gcc)
==13165==    by 0x8052791: (within /usr/bin/gcc)
==13165==
==13165==
==13165== 76 bytes in 2 blocks are still reachable in loss record 3 of 6
==13165==    at 0x40046FF: calloc (vg_replace_malloc.c:279)
==13165==    by 0x806082B: (within /usr/bin/gcc)
==13165==    by 0x8056079: (within /usr/bin/gcc)
==13165==    by 0x8055A66: (within /usr/bin/gcc)
==13165==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13165==
==13165==
==13165== 144 bytes in 2 blocks are still reachable in loss record 4 of 6
==13165==    at 0x40054BB: realloc (vg_replace_malloc.c:306)
==13165==    by 0x80607D2: (within /usr/bin/gcc)
==13165==    by 0x8053061: (within /usr/bin/gcc)
==13165==    by 0x80532B1: (within /usr/bin/gcc)
==13165==    by 0x80539AF: (within /usr/bin/gcc)
==13165==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13165==
==13165==
==13165== 3,423 (3,407 direct, 16 indirect) bytes in 26 blocks are definitely lost in loss record 5 of 6
==13165==    at 0x40053C0: malloc (vg_replace_malloc.c:149)
==13165==    by 0x8060877: (within /usr/bin/gcc)
==13165==    by 0x804B380: (within /usr/bin/gcc)
==13165==    by 0x8053833: (within /usr/bin/gcc)
==13165==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13165==
==13165==
==13165== 14,804 bytes in 38 blocks are still reachable in loss record 6 of 6
==13165==    at 0x40053C0: malloc (vg_replace_malloc.c:149)
==13165==    by 0x8060877: (within /usr/bin/gcc)
==13165==    by 0x683457: _obstack_begin (in /lib/libc-2.5.so)
==13165==    by 0x80534B1: (within /usr/bin/gcc)
==13165==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13165==
==13165== LEAK SUMMARY:
==13165==    definitely lost: 3,408 bytes in 27 blocks.
==13165==    indirectly lost: 16 bytes in 1 blocks.
==13165==      possibly lost: 0 bytes in 0 blocks.
==13165==    still reachable: 15,024 bytes in 42 blocks.
==13165==         suppressed: 0 bytes in 0 blocks.
--13165--  memcheck: sanity checks: 1 cheap, 1 expensive
--13165--  memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
--13165--  memcheck: auxmaps: 0 searches, 0 comparisons
--13165--  memcheck: SMs: n_issued      = 11 (176k, 0M)
--13165--  memcheck: SMs: n_deissued    = 0 (0k, 0M)
--13165--  memcheck: SMs: max_noaccess  = 65535 (1048560k, 1023M)
--13165--  memcheck: SMs: max_undefined = 0 (0k, 0M)
--13165--  memcheck: SMs: max_defined   = 53 (848k, 0M)
--13165--  memcheck: SMs: max_non_DSM   = 11 (176k, 0M)
--13165--  memcheck: max sec V bit nodes:    0 (0k, 0M)
--13165--  memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0)
--13165--  memcheck: max shadow mem size:   480k, 0M
--13165-- translate:            fast SP updates identified: 3,704 ( 88.7%)
--13165-- translate:   generic_known SP updates identified: 301 (  7.2%)
--13165-- translate: generic_unknown SP updates identified: 169 (  4.0%)
--13165--     tt/tc: 8,799 tt lookups requiring 8,992 probes
--13165--     tt/tc: 8,799 fast-cache updates, 3 flushes
--13165--  transtab: new        4,266 (84,609 -> 1,408,480; ratio 166:10) [0 scs]
--13165--  transtab: dumped     0 (0 -> ??)
--13165--  transtab: discarded  6 (146 -> ??)
--13165-- scheduler: 174,383 jumps (bb entries).
--13165-- scheduler: 1/5,081 major/minor sched events.
--13165--    sanity: 2 cheap, 1 expensive checks.
--13165--    exectx: 30,011 lists, 256 contexts (avg 0 per list)
--13165--    exectx: 360 searches, 105 full compares (291 per 1000)
--13165--    exectx: 107 cmp2, 37 cmp4, 0 cmpAll
[snooc@pluto ~]$ clear
[snooc@pluto ~]$ valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes  gcc -Wall -o exx exx.c
[snooc@pluto ~]$
[snooc@pluto ~]$ valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes  gcc -Wall -o exx exx.c
==13171== Memcheck, a memory error detector.
==13171== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==13171== Using LibVEX rev 1658, a library for dynamic binary translation.
==13171== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==13171== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==13171== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==13171==
--13171-- Command line
--13171--    gcc
--13171--    -Wall
--13171--    -o
--13171--    exx
--13171--    exx.c
--13171-- Startup, with flags:
--13171--    -v
--13171--    --tool=memcheck
--13171--    --leak-check=full
--13171--    --show-reachable=yes
--13171-- Contents of /proc/version:
--13171--   Linux version 2.6.18-164.2.1.el5.plus (mockbuild@builder16.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Fri Oct 9 12:34:43 EDT 2009
--13171-- Arch and hwcaps: X86, x86-sse1-sse2
--13171-- Valgrind library directory: /usr/lib/valgrind
--13171-- Reading syms from /lib/ld-2.5.so (0x5F6000)
--13171-- Reading syms from /usr/bin/gcc (0x8047000)
--13171--    object doesn't have a symbol table
--13171-- Reading syms from /usr/lib/valgrind/x86-linux/memcheck (0x38000000)
--13171--    object doesn't have a dynamic symbol table
--13171-- Reading suppressions file: /usr/lib/valgrind/default.supp
--13171-- REDIR: 0x60B790 (index) redirected to 0x38027D0F (vgPlain_x86_linux_REDIR_FOR_index)
--13171-- Reading syms from /usr/lib/valgrind/x86-linux/vgpreload_core.so (0x4001000)
--13171-- Reading syms from /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so (0x4003000)
==13171== WARNING: new redirection conflicts with existing -- ignoring it
--13171--     new: 0x0060B790 (index     ) R-> 0x04006080 index
--13171-- REDIR: 0x60B930 (strlen) redirected to 0x4006250 (strlen)
--13171-- Reading syms from /lib/libc-2.5.so (0x614000)
--13171-- REDIR: 0x684430 (rindex) redirected to 0x4005F60 (rindex)
--13171-- REDIR: 0x684090 (strlen) redirected to 0x4006230 (strlen)
--13171-- REDIR: 0x67FD20 (malloc) redirected to 0x400533B (malloc)
--13171-- REDIR: 0x684280 (strncmp) redirected to 0x4006290 (strncmp)
--13171-- REDIR: 0x67D980 (free) redirected to 0x4004F55 (free)
--13171-- REDIR: 0x683B30 (strcmp) redirected to 0x4006300 (strcmp)
--13171-- REDIR: 0x6839C0 (index) redirected to 0x4006050 (index)
--13171-- REDIR: 0x686140 (strchrnul) redirected to 0x40065D0 (strchrnul)
--13171-- REDIR: 0x6857C0 (memcpy) redirected to 0x4006C20 (memcpy)
--13171-- REDIR: 0x6854C0 (stpcpy) redirected to 0x40068D0 (stpcpy)
--13171-- REDIR: 0x684140 (strnlen) redirected to 0x4006200 (strnlen)
--13171-- REDIR: 0x683BA0 (strcpy) redirected to 0x40069B0 (strcpy)
--13171-- REDIR: 0x684DD0 (memchr) redirected to 0x4006420 (memchr)
--13171-- REDIR: 0x680190 (realloc) redirected to 0x40053EA (realloc)
--13171-- REDIR: 0x686070 (rawmemchr) redirected to 0x4006600 (rawmemchr)
--13171-- REDIR: 0x6852D0 (memset) redirected to 0x4006540 (memset)
--13171-- REDIR: 0x684380 (strncpy) redirected to 0x4006DA0 (strncpy)
--13171-- REDIR: 0x683810 (strcat) redirected to 0x4006620 (strcat)
--13171-- REDIR: 0x67F9E0 (calloc) redirected to 0x4004668 (calloc)
exx.c: In function âmainâ:
exx.c:17: warning: unused variable âmod_strlenâ
exx.c: In function âgetInputâ:
exx.c:49: warning: unused variable âtextâ
exx.c: At top level:
exx.c:150: error: redefinition of âlenstrâ
exx.c:140: error: previous definition of âlenstrâ was here
exx.c:161: error: redefinition of âmainâ
exx.c:14: error: previous definition of âmainâ was here
==13171==
==13171== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 1)
--13171--
--13171-- supp:   12 Fedora-Core-6-hack3-ld25
==13171== malloc/free: in use at exit: 18,448 bytes in 70 blocks.
==13171== malloc/free: 209 allocs, 139 frees, 28,785 bytes allocated.
==13171==
==13171== searching for pointers to 70 not-freed blocks.
==13171== checked 54,332 bytes.
==13171==
==13171== 1 bytes in 1 blocks are definitely lost in loss record 1 of 6
==13171==    at 0x40046FF: calloc (vg_replace_malloc.c:279)
==13171==    by 0x806082B: (within /usr/bin/gcc)
==13171==    by 0x8053EB4: (within /usr/bin/gcc)
==13171==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13171==
==13171==
==13171== 16 bytes in 1 blocks are indirectly lost in loss record 2 of 6
==13171==    at 0x40053C0: malloc (vg_replace_malloc.c:149)
==13171==    by 0x8060877: (within /usr/bin/gcc)
==13171==    by 0x80608F1: (within /usr/bin/gcc)
==13171==    by 0x8049572: (within /usr/bin/gcc)
==13171==    by 0x804B086: (within /usr/bin/gcc)
==13171==    by 0x8050266: (within /usr/bin/gcc)
==13171==    by 0x8052791: (within /usr/bin/gcc)
==13171==    by 0x80501C6: (within /usr/bin/gcc)
==13171==    by 0x8050313: (within /usr/bin/gcc)
==13171==    by 0x8052791: (within /usr/bin/gcc)
==13171==    by 0x80501C6: (within /usr/bin/gcc)
==13171==    by 0x8052791: (within /usr/bin/gcc)
==13171==
==13171==
==13171== 76 bytes in 2 blocks are still reachable in loss record 3 of 6
==13171==    at 0x40046FF: calloc (vg_replace_malloc.c:279)
==13171==    by 0x806082B: (within /usr/bin/gcc)
==13171==    by 0x8056079: (within /usr/bin/gcc)
==13171==    by 0x8055A66: (within /usr/bin/gcc)
==13171==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13171==
==13171==
==13171== 144 bytes in 2 blocks are still reachable in loss record 4 of 6
==13171==    at 0x40054BB: realloc (vg_replace_malloc.c:306)
==13171==    by 0x80607D2: (within /usr/bin/gcc)
==13171==    by 0x8053061: (within /usr/bin/gcc)
==13171==    by 0x80532B1: (within /usr/bin/gcc)
==13171==    by 0x80539AF: (within /usr/bin/gcc)
==13171==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13171==
==13171==
==13171== 3,423 (3,407 direct, 16 indirect) bytes in 26 blocks are definitely lost in loss record 5 of 6
==13171==    at 0x40053C0: malloc (vg_replace_malloc.c:149)
==13171==    by 0x8060877: (within /usr/bin/gcc)
==13171==    by 0x804B380: (within /usr/bin/gcc)
==13171==    by 0x8053833: (within /usr/bin/gcc)
==13171==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13171==
==13171==
==13171== 14,804 bytes in 38 blocks are still reachable in loss record 6 of 6
==13171==    at 0x40053C0: malloc (vg_replace_malloc.c:149)
==13171==    by 0x8060877: (within /usr/bin/gcc)
==13171==    by 0x683457: _obstack_begin (in /lib/libc-2.5.so)
==13171==    by 0x80534B1: (within /usr/bin/gcc)
==13171==    by 0x629E9B: (below main) (in /lib/libc-2.5.so)
==13171==
==13171== LEAK SUMMARY:
==13171==    definitely lost: 3,408 bytes in 27 blocks.
==13171==    indirectly lost: 16 bytes in 1 blocks.
==13171==      possibly lost: 0 bytes in 0 blocks.
==13171==    still reachable: 15,024 bytes in 42 blocks.
==13171==         suppressed: 0 bytes in 0 blocks.
--13171--  memcheck: sanity checks: 1 cheap, 1 expensive
--13171--  memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
--13171--  memcheck: auxmaps: 0 searches, 0 comparisons
--13171--  memcheck: SMs: n_issued      = 11 (176k, 0M)
--13171--  memcheck: SMs: n_deissued    = 0 (0k, 0M)
--13171--  memcheck: SMs: max_noaccess  = 65535 (1048560k, 1023M)
--13171--  memcheck: SMs: max_undefined = 0 (0k, 0M)
--13171--  memcheck: SMs: max_defined   = 53 (848k, 0M)
--13171--  memcheck: SMs: max_non_DSM   = 11 (176k, 0M)
--13171--  memcheck: max sec V bit nodes:    0 (0k, 0M)
--13171--  memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0)
--13171--  memcheck: max shadow mem size:   480k, 0M
--13171-- translate:            fast SP updates identified: 3,704 ( 88.7%)
--13171-- translate:   generic_known SP updates identified: 301 (  7.2%)
--13171-- translate: generic_unknown SP updates identified: 169 (  4.0%)
--13171--     tt/tc: 8,801 tt lookups requiring 8,994 probes
--13171--     tt/tc: 8,801 fast-cache updates, 3 flushes
--13171--  transtab: new        4,267 (84,610 -> 1,408,370; ratio 166:10) [0 scs]
--13171--  transtab: dumped     0 (0 -> ??)
--13171--  transtab: discarded  6 (146 -> ??)
--13171-- scheduler: 174,384 jumps (bb entries).
--13171-- scheduler: 1/5,082 major/minor sched events.
--13171--    sanity: 2 cheap, 1 expensive checks.
--13171--    exectx: 30,011 lists, 256 contexts (avg 0 per list)
--13171--    exectx: 360 searches, 105 full compares (291 per 1000)
--13171--    exectx: 107 cmp2, 37 cmp4, 0 cmpAll
Am Anfang der Weisheit steht die eigene Erkenntnis, dass man selbst nichts weiß! - Sokrates

43

18.11.2009, 21:31

also ich muss gestehn, dass für mich die beiden funktionen richtig ausschaun...

bist du dir ganz sicher dass das ganze programm lauft und dann beim free ein segfault kommt.
hast im ganzen code immer wieder debug printfs gmacht um zu schaun wie weit er wirkli geht?
vielleicht bleibt er viel früher schon wo stehn...

lg

$nooc

Alter Hase

  • »$nooc« ist der Autor dieses Themas

Beiträge: 873

Wohnort: Österreich / Kärnten

Beruf: Schüler

  • Private Nachricht senden

44

18.11.2009, 21:35

nein das ist es ja..
in meinem string den ich dem programm übergebe ist nur 1 '@' zeichen..

das heißt shiftString() wird dabei nur 1mal ausgeführt..
das läuft, string sieht auch richtig aus..
dann ist die funktion vorbei..

modifyString() läuft fertig (pointer ist immer noch ok)
wenn ich beim return der funktion haltepunkt setze, ist der pointer sowie der string ok..

modifyString() ist fertig, übergibt die adresse

output = modifyString(output);

noch immer alles ok, und dann beim free(output) ist dann ende im gelände.. :(
Am Anfang der Weisheit steht die eigene Erkenntnis, dass man selbst nichts weiß! - Sokrates

45

19.11.2009, 23:42

Ansich kann ich da auch eigentlich nichts fehlerhaftes erkennen, bis auf dass die Funktionenen teilweise doppelt und mit unterschiedlichem Code vorkommen (zb. main).

Du könntest ja versuchen nach jedem realloc auszugeben an welcher Adresse dein Speicher startet und dann vergleichen ob beim free am Schluss auch noch immer der richtige Zeiger vom letzten realloc ankommt.

Zitat von »"dot"«

Hah! Ich weis auch wen ;)

Und ich weiß auch woher :D
Tutorials zu OpenGL, Ubuntu und Programmieren allgemein: www.tomprogs.at

Forum und Wiki zum Programmieren lernen: proggen.org/forum.proggen.org

Werbeanzeige