Skip to content

Commit

Permalink
Clean up mode tracking to avoid a small memory leak.
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Oct 22, 2013
1 parent 0cb534d commit 1e0d304
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/usb_moded-dbus.c
Expand Up @@ -74,10 +74,11 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa

if(!strcmp(member, USB_MODE_STATE_REQUEST))
{
const char *mode = get_usb_mode();
const char *mode = strdup(get_usb_mode());

if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
free((void *)mode);
}
else if(!strcmp(member, USB_MODE_STATE_SET))
{
Expand Down
14 changes: 6 additions & 8 deletions src/usb_moded.c
Expand Up @@ -322,8 +322,7 @@ void set_usb_mode(const char *mode)
}
if(net)
log_debug("Network setting failed!\n");
free(current_mode.mode);
current_mode.mode = strdup(mode);
current_mode.mode = mode;
usb_moded_send_signal(get_usb_mode());
}

Expand Down Expand Up @@ -406,8 +405,8 @@ inline const char * get_usb_mode(void)
*/
void set_usb_module(const char *module)
{
free(current_mode.module);
current_mode.module = strdup(module);
//free(current_mode.module);
current_mode.module = module;
}

/** get the supposedly loaded module
Expand Down Expand Up @@ -469,8 +468,8 @@ static void usb_moded_init(void)

current_mode.connected = FALSE;
current_mode.mounted = FALSE;
current_mode.mode = strdup(MODE_UNDEFINED);
current_mode.module = strdup(MODULE_NONE);
current_mode.mode = MODE_UNDEFINED;
current_mode.module = MODULE_NONE;

/* check config, merge or create if outdated */
if(conf_file_merge() != 0)
Expand Down Expand Up @@ -518,8 +517,7 @@ static gboolean charging_fallback(gpointer data)
/* since this is the fallback, we keep an indication
for the UI, as we are not really in charging mode.
*/
free(current_mode.mode);
current_mode.mode = strdup(MODE_ASK);
current_mode.mode = MODE_ASK;
current_mode.data = NULL;
charging_timeout = 0;
log_info("Falling back on charging mode.\n");
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded.h
Expand Up @@ -48,8 +48,8 @@ typedef struct usb_mode
/*@{*/
gboolean connected; /* connection status, 1 for connected */
gboolean mounted; /* mount status, 1 for mounted -UNUSED atm- */
char *mode; /* the mode name */
char *module; /* the module name for the specific mode */
const char *mode; /* the mode name */
const char *module; /* the module name for the specific mode */
struct mode_list_elem *data; /* contains the mode data */
/*@}*/
}usb_mode;
Expand Down

0 comments on commit 1e0d304

Please sign in to comment.