Hi, Michael! On Jun 16, Michael Widenius wrote: > > > Hi! > > >>>>> "serg" == serg <[email protected]> writes: > > serg> At http://bazaar.launchpad.net/~maria-captains/maria/5.1/ > serg> ------------------------------------------------------------ > serg> revno: 2866 > serg> revision-id: [email protected] > serg> parent: [email protected] > serg> committer: Sergei Golubchik <[email protected]> > serg> branch nick: 5.1 > serg> timestamp: Mon 2010-06-14 11:18:54 +0200 > serg> message: > serg> mysqltest: use setenv, not putenv, to make gcov happy. > serg> (backport from MySQL) > > +static int setenv(const char *name, const char *value, int overwrite) > +{ > + size_t buflen= strlen(name) + strlen(value) + 2; > + char *envvar= (char *)malloc(buflen); > + if(!envvar) > + return ENOMEM; > + strcpy(envvar, name); > + strcat(envvar, "="); > + strcat(envvar, value); > + putenv(envvar); > + return 0; > +} > +#endif > > I expected better from you :)
It's not from me, it's copied from MySQL. My code had only #ifndef HAVE_SETENV #error implement our portable setenv replacement in mysys #endif which passed with flying colors on all PB2 hosts as far as I remember. Still, somebody added an "our portable setenv replacement" later, so apparently some strange systems didn't have a setenv(). > A much better version is: > > strcat(strcat(strmov(envvar, name), "="), value); > > The other question I have is will this not cause a memory leek? > If we allocate the same string many times in here it will definitely > be a memory leak as putenv() will never free the old value. Yes, it will. But who cares if on some strange system a mysqltest binary will not free a hundred of bytes explicitly and let them be freed whan an executable exits ? Most probably. valgrind isn't even to them. What *is* important is not to free environment variable values explicitly on systems where gcov exists - which was the reason for me to change putenv() to setenv() in the first place. Regards, Sergei _______________________________________________ Mailing list: https://launchpad.net/~maria-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~maria-developers More help : https://help.launchpad.net/ListHelp

