Skip to content

Commit

Permalink
Revert "Clean up mode tracking to avoid a small memory leak."
Browse files Browse the repository at this point in the history
As it might actually be responsible for some weird behaviour and
crashes we have seen lately.

This reverts commit 1e0d304.

Conflicts:
	src/usb_moded-dbus.c
  • Loading branch information
philippedeswert committed Oct 29, 2013
1 parent e6b10e2 commit 1b1baea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 2 additions & 5 deletions src/usb_moded-dbus.c
Expand Up @@ -42,7 +42,6 @@ extern gboolean rescue_mode;

static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
const char *mode = NULL;
DBusHandlerResult status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
DBusMessage *reply = 0;
const char *interface = dbus_message_get_interface(msg);
Expand Down Expand Up @@ -75,10 +74,11 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa

if(!strcmp(member, USB_MODE_STATE_REQUEST))
{
mode = strdup(get_usb_mode()); /* freed at the end after sending the message */
const char *mode = 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 Expand Up @@ -228,9 +228,6 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
dbus_message_unref(reply);
}

if(mode)
free((void *)mode);

return status;
}

Expand Down
14 changes: 8 additions & 6 deletions src/usb_moded.c
Expand Up @@ -325,7 +325,8 @@ void set_usb_mode(const char *mode)
}
if(net)
log_debug("Network setting failed!\n");
current_mode.mode = mode;
free(current_mode.mode);
current_mode.mode = strdup(mode);
usb_moded_send_signal(get_usb_mode());
}

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

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

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

/* check config, merge or create if outdated */
if(conf_file_merge() != 0)
Expand Down Expand Up @@ -520,7 +521,8 @@ 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.
*/
current_mode.mode = MODE_ASK;
free(current_mode.mode);
current_mode.mode = strdup(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- */
const char *mode; /* the mode name */
const char *module; /* the module name for the specific mode */
char *mode; /* the mode name */
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 1b1baea

Please sign in to comment.