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 :)

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

_______________________________________________
Mailing list: https://launchpad.net/~maria-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to