Bernhard Herzog wrote: > "Java and Swing" <[EMAIL PROTECTED]> writes: > > > char *foo(const char *in) { > > char *tmp; > > tmp = (char *) malloc((strlen(in) * sizeof(char)) + 1); > > strcpy(tmp, in); > > ... > > ... > > free(tmp); > > return someValue; > > } > > > > Is that appropriate? I was under the impression that when you malloc > > memory, you free it when done. > > Looks fine. I hope someValue does not point somewhere into the tmp > buffer, though.
someValue doesn't. > > > I also have things like... > > > > char *bar(char *in) { > > char *results, *finalResults; > > results = (char *) malloc(...); > > finalResults = results; > > > > while (...) { *results++ = some_val; } > > > > return finalResults; > > } > > Seems OK, too, assuming the results buffer is big enough. results = (char *) malloc((sizeof(char) * strlen(in) + 1); ..should be big enough. At any rate, it works four times in a row before it fails. I wonder what else or how else to solve this. Why is malloc'ing the memory crashing it!? -- http://mail.python.org/mailman/listinfo/python-list