maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #03272
[Commits] Rev 2866: mysqltest: use setenv, not putenv, to make gcov happy. in http://bazaar.launchpad.net/~maria-captains/maria/5.1/
Hi!
>>>>> "serg" == serg <serg@xxxxxxxxxxxx> writes:
serg> At http://bazaar.launchpad.net/~maria-captains/maria/5.1/
serg> ------------------------------------------------------------
serg> revno: 2866
serg> revision-id: sergii@xxxxxxxxx-20100614091854-5ynq6lo943qlaacw
serg> parent: monty@xxxxxxxxxxxx-20100613221332-ldsnptg0j0mn8u9a
serg> committer: Sergei Golubchik <sergii@xxxxxxxxx>
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 :)
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.
Regards,
Monty
Follow ups