In smbc_free_context libsmbclient just called free() on the string options
so it assumes the callers have malloced them before setting them via smbc_set
calls.
Change to corretly malloc/free string options to the library.
Jeremy
}
/* Things we have to clean up */
}
/* Things we have to clean up */
- free(smbc_getWorkgroup(context));
smbc_setWorkgroup(context, NULL);
smbc_setWorkgroup(context, NULL);
-
- free(smbc_getNetbiosName(context));
smbc_setNetbiosName(context, NULL);
smbc_setNetbiosName(context, NULL);
-
- free(smbc_getUser(context));
smbc_setUser(context, NULL);
DEBUG(3, ("Context %p successfully freed\n", context));
smbc_setUser(context, NULL);
DEBUG(3, ("Context %p successfully freed\n", context));
smbc_init_context(SMBCCTX *context)
{
int pid;
smbc_init_context(SMBCCTX *context)
{
int pid;
if (!context) {
errno = EBADF;
if (!context) {
errno = EBADF;
/*
* FIXME: Is this the best way to get the user info?
*/
/*
* FIXME: Is this the best way to get the user info?
*/
+ char *user = getenv("USER");
/* walk around as "guest" if no username can be found */
if (!user) {
user = SMB_STRDUP("guest");
/* walk around as "guest" if no username can be found */
if (!user) {
user = SMB_STRDUP("guest");
}
smbc_setUser(context, user);
}
smbc_setUser(context, user);
+ SAFE_FREE(user);
+
+ if (!smbc_getUser(context)) {
+ errno = ENOMEM;
+ return NULL;
+ }
}
if (!smbc_getNetbiosName(context)) {
}
if (!smbc_getNetbiosName(context)) {
}
smbc_setNetbiosName(context, netbios_name);
}
smbc_setNetbiosName(context, netbios_name);
+ SAFE_FREE(netbios_name);
+
+ if (!smbc_getNetbiosName(context)) {
+ errno = ENOMEM;
+ return NULL;
+ }
}
DEBUG(1, ("Using netbios name %s.\n", smbc_getNetbiosName(context)));
}
DEBUG(1, ("Using netbios name %s.\n", smbc_getNetbiosName(context)));
}
smbc_setWorkgroup(context, workgroup);
}
smbc_setWorkgroup(context, workgroup);
+ SAFE_FREE(workgroup);
+
+ if (!smbc_getWorkgroup(context)) {
+ errno = ENOMEM;
+ return NULL;
+ }
}
DEBUG(1, ("Using workgroup %s.\n", smbc_getWorkgroup(context)));
}
DEBUG(1, ("Using workgroup %s.\n", smbc_getWorkgroup(context)));
void
smbc_setNetbiosName(SMBCCTX *c, char * netbios_name)
{
void
smbc_setNetbiosName(SMBCCTX *c, char * netbios_name)
{
- c->netbios_name = netbios_name;
+ SAFE_FREE(c->netbios_name);
+ c->netbios_name = SMB_STRDUP(netbios_name);
}
/** Get the workgroup used for making connections */
}
/** Get the workgroup used for making connections */
void
smbc_setWorkgroup(SMBCCTX *c, char * workgroup)
{
void
smbc_setWorkgroup(SMBCCTX *c, char * workgroup)
{
- c->workgroup = workgroup;
+ SAFE_FREE(c->workgroup);
+ c->workgroup = SMB_STRDUP(workgroup);
}
/** Get the username used for making connections */
}
/** Get the username used for making connections */
void
smbc_setUser(SMBCCTX *c, char * user)
{
void
smbc_setUser(SMBCCTX *c, char * user)
{
+ SAFE_FREE(c->user);
+ c->user = SMB_STRDUP(user);
}
/** Get the debug level */
}
/** Get the debug level */