All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Move phonebook_req_finalize
@ 2011-05-18 15:58 Dmitriy Paliy
  2011-05-18 15:58 ` [PATCH 2/3] Fix numbers GSlist to be used in new missed calls Dmitriy Paliy
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dmitriy Paliy @ 2011-05-18 15:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

It is used in successive patch.
---
 plugins/phonebook-tracker.c |   40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 9431d8a..9c60ec3 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1905,26 +1905,6 @@ done:
 	return path;
 }
 
-void phonebook_req_finalize(void *request)
-{
-	struct phonebook_data *data = request;
-
-	DBG("");
-
-	if (!data)
-		return;
-
-	/* canceling asynchronous operation on tracker if any is active */
-	if (data->query_canc) {
-		g_cancellable_cancel(data->query_canc);
-		g_object_unref(data->query_canc);
-	}
-
-	free_data_contacts(data);
-	g_free(data->req_name);
-	g_free(data);
-}
-
 static gboolean find_checked_number(GSList *numbers, const char *number)
 {
 	GSList *l;
@@ -1996,6 +1976,26 @@ done:
 	return 0;
 }
 
+void phonebook_req_finalize(void *request)
+{
+	struct phonebook_data *data = request;
+
+	DBG("");
+
+	if (!data)
+		return;
+
+	/* canceling asynchronous operation on tracker if any is active */
+	if (data->query_canc) {
+		g_cancellable_cancel(data->query_canc);
+		g_object_unref(data->query_canc);
+	}
+
+	free_data_contacts(data);
+	g_free(data->req_name);
+	g_free(data);
+}
+
 void *phonebook_pull(const char *name, const struct apparam_field *params,
 				phonebook_cb cb, void *user_data, int *err)
 {
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] Fix numbers GSlist to be used in new missed calls
  2011-05-18 15:58 [PATCH 1/3] Move phonebook_req_finalize Dmitriy Paliy
@ 2011-05-18 15:58 ` Dmitriy Paliy
  2011-05-19  7:29   ` Luiz Augusto von Dentz
  2011-05-18 15:58 ` [PATCH 3/3] Change append to prepend in pull_newmissedcalls Dmitriy Paliy
  2011-05-19  7:27 ` [PATCH 1/3] Move phonebook_req_finalize Luiz Augusto von Dentz
  2 siblings, 1 reply; 5+ messages in thread
From: Dmitriy Paliy @ 2011-05-18 15:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

It is possible that phonebook_pull_read is invoked several times
submitting multiple pull requests without closing PBAP object. E.g. when
maxlistcount value is small and size of call history is large enough.

The result is possibility of different data structures (gstring and
contact_data) to be mixed in a single GSlist that may lead to undefined
behaviour.
---
 plugins/phonebook-tracker.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 9c60ec3..52ed31b 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -948,6 +948,7 @@ struct phonebook_data {
 	gboolean vcardentry;
 	const struct apparam_field *params;
 	GSList *contacts;
+	GSList *numbers;
 	phonebook_cache_ready_cb ready_cb;
 	phonebook_entry_cb entry_cb;
 	int newmissedcalls;
@@ -1923,6 +1924,13 @@ static void gstring_free_helper(gpointer data, gpointer user_data)
 	g_string_free(data, TRUE);
 }
 
+static void free_data_numbers(struct phonebook_data *data)
+{
+	g_slist_foreach(data->numbers, gstring_free_helper, NULL);
+	g_slist_free(data->numbers);
+	data->numbers = NULL;
+}
+
 static int pull_newmissedcalls(const char **reply, int num_fields,
 							void *user_data)
 {
@@ -1934,12 +1942,12 @@ static int pull_newmissedcalls(const char **reply, int num_fields,
 	if (num_fields < 0 || reply == NULL)
 		goto done;
 
-	if (!find_checked_number(data->contacts, reply[1])) {
+	if (!find_checked_number(data->numbers, reply[1])) {
 		if (g_strcmp0(reply[2], "false") == 0)
 			data->newmissedcalls++;
 		else {
 			GString *number = g_string_new(reply[1]);
-			data->contacts = g_slist_append(data->contacts,
+			data->numbers = g_slist_append(data->numbers,
 								number);
 		}
 	}
@@ -1947,9 +1955,7 @@ static int pull_newmissedcalls(const char **reply, int num_fields,
 
 done:
 	DBG("newmissedcalls %d", data->newmissedcalls);
-	g_slist_foreach(data->contacts, gstring_free_helper, NULL);
-	g_slist_free(data->contacts);
-	data->contacts = NULL;
+	free_data_numbers(data);
 
 	if (num_fields < 0) {
 		data->cb(NULL, 0, num_fields, 0, TRUE, data->user_data);
@@ -1991,6 +1997,7 @@ void phonebook_req_finalize(void *request)
 		g_object_unref(data->query_canc);
 	}
 
+	free_data_numbers(data);
 	free_data_contacts(data);
 	g_free(data->req_name);
 	g_free(data);
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] Change append to prepend in pull_newmissedcalls
  2011-05-18 15:58 [PATCH 1/3] Move phonebook_req_finalize Dmitriy Paliy
  2011-05-18 15:58 ` [PATCH 2/3] Fix numbers GSlist to be used in new missed calls Dmitriy Paliy
@ 2011-05-18 15:58 ` Dmitriy Paliy
  2011-05-19  7:27 ` [PATCH 1/3] Move phonebook_req_finalize Luiz Augusto von Dentz
  2 siblings, 0 replies; 5+ messages in thread
From: Dmitriy Paliy @ 2011-05-18 15:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

---
 plugins/phonebook-tracker.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 52ed31b..d5cdc15 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1947,7 +1947,7 @@ static int pull_newmissedcalls(const char **reply, int num_fields,
 			data->newmissedcalls++;
 		else {
 			GString *number = g_string_new(reply[1]);
-			data->numbers = g_slist_append(data->numbers,
+			data->numbers = g_slist_prepend(data->numbers,
 								number);
 		}
 	}
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] Move phonebook_req_finalize
  2011-05-18 15:58 [PATCH 1/3] Move phonebook_req_finalize Dmitriy Paliy
  2011-05-18 15:58 ` [PATCH 2/3] Fix numbers GSlist to be used in new missed calls Dmitriy Paliy
  2011-05-18 15:58 ` [PATCH 3/3] Change append to prepend in pull_newmissedcalls Dmitriy Paliy
@ 2011-05-19  7:27 ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2011-05-19  7:27 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth

Hi Dmitriy,

On Wed, May 18, 2011 at 6:58 PM, Dmitriy Paliy <dmitriy.paliy@nokia.com> wrote:
> It is used in successive patch.
> ---
>  plugins/phonebook-tracker.c |   40 ++++++++++++++++++++--------------------
>  1 files changed, 20 insertions(+), 20 deletions(-)
>
> diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
> index 9431d8a..9c60ec3 100644
> --- a/plugins/phonebook-tracker.c
> +++ b/plugins/phonebook-tracker.c
> @@ -1905,26 +1905,6 @@ done:
>        return path;
>  }
>
> -void phonebook_req_finalize(void *request)
> -{
> -       struct phonebook_data *data = request;
> -
> -       DBG("");
> -
> -       if (!data)
> -               return;
> -
> -       /* canceling asynchronous operation on tracker if any is active */
> -       if (data->query_canc) {
> -               g_cancellable_cancel(data->query_canc);
> -               g_object_unref(data->query_canc);
> -       }
> -
> -       free_data_contacts(data);
> -       g_free(data->req_name);
> -       g_free(data);
> -}
> -
>  static gboolean find_checked_number(GSList *numbers, const char *number)
>  {
>        GSList *l;
> @@ -1996,6 +1976,26 @@ done:
>        return 0;
>  }
>
> +void phonebook_req_finalize(void *request)
> +{
> +       struct phonebook_data *data = request;
> +
> +       DBG("");
> +
> +       if (!data)
> +               return;
> +
> +       /* canceling asynchronous operation on tracker if any is active */
> +       if (data->query_canc) {
> +               g_cancellable_cancel(data->query_canc);
> +               g_object_unref(data->query_canc);
> +       }
> +
> +       free_data_contacts(data);
> +       g_free(data->req_name);
> +       g_free(data);
> +}
> +
>  void *phonebook_pull(const char *name, const struct apparam_field *params,
>                                phonebook_cb cb, void *user_data, int *err)
>  {
> --

It should be fine to have 1 and 2 together, it is less troublesome if
somebody is using git blame to check the history.

-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] Fix numbers GSlist to be used in new missed calls
  2011-05-18 15:58 ` [PATCH 2/3] Fix numbers GSlist to be used in new missed calls Dmitriy Paliy
@ 2011-05-19  7:29   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2011-05-19  7:29 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth

Hi,

On Wed, May 18, 2011 at 6:58 PM, Dmitriy Paliy <dmitriy.paliy@nokia.com> wrote:
> It is possible that phonebook_pull_read is invoked several times
> submitting multiple pull requests without closing PBAP object. E.g. when
> maxlistcount value is small and size of call history is large enough.
>
> The result is possibility of different data structures (gstring and
> contact_data) to be mixed in a single GSlist that may lead to undefined
> behaviour.
> ---
>  plugins/phonebook-tracker.c |   17 ++++++++++++-----
>  1 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
> index 9c60ec3..52ed31b 100644
> --- a/plugins/phonebook-tracker.c
> +++ b/plugins/phonebook-tracker.c
> @@ -948,6 +948,7 @@ struct phonebook_data {
>        gboolean vcardentry;
>        const struct apparam_field *params;
>        GSList *contacts;
> +       GSList *numbers;
>        phonebook_cache_ready_cb ready_cb;
>        phonebook_entry_cb entry_cb;
>        int newmissedcalls;
> @@ -1923,6 +1924,13 @@ static void gstring_free_helper(gpointer data, gpointer user_data)
>        g_string_free(data, TRUE);
>  }
>
> +static void free_data_numbers(struct phonebook_data *data)
> +{
> +       g_slist_foreach(data->numbers, gstring_free_helper, NULL);
> +       g_slist_free(data->numbers);
> +       data->numbers = NULL;
> +}
> +
>  static int pull_newmissedcalls(const char **reply, int num_fields,
>                                                        void *user_data)
>  {
> @@ -1934,12 +1942,12 @@ static int pull_newmissedcalls(const char **reply, int num_fields,
>        if (num_fields < 0 || reply == NULL)
>                goto done;
>
> -       if (!find_checked_number(data->contacts, reply[1])) {
> +       if (!find_checked_number(data->numbers, reply[1])) {
>                if (g_strcmp0(reply[2], "false") == 0)
>                        data->newmissedcalls++;
>                else {
>                        GString *number = g_string_new(reply[1]);
> -                       data->contacts = g_slist_append(data->contacts,
> +                       data->numbers = g_slist_append(data->numbers,
>                                                                number);
>                }
>        }
> @@ -1947,9 +1955,7 @@ static int pull_newmissedcalls(const char **reply, int num_fields,
>
>  done:
>        DBG("newmissedcalls %d", data->newmissedcalls);
> -       g_slist_foreach(data->contacts, gstring_free_helper, NULL);
> -       g_slist_free(data->contacts);
> -       data->contacts = NULL;
> +       free_data_numbers(data);
>
>        if (num_fields < 0) {
>                data->cb(NULL, 0, num_fields, 0, TRUE, data->user_data);
> @@ -1991,6 +1997,7 @@ void phonebook_req_finalize(void *request)
>                g_object_unref(data->query_canc);
>        }
>
> +       free_data_numbers(data);
>        free_data_contacts(data);
>        g_free(data->req_name);
>        g_free(data);
> --
> 1.7.4.1

Looks much better, ack.


-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-05-19  7:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-18 15:58 [PATCH 1/3] Move phonebook_req_finalize Dmitriy Paliy
2011-05-18 15:58 ` [PATCH 2/3] Fix numbers GSlist to be used in new missed calls Dmitriy Paliy
2011-05-19  7:29   ` Luiz Augusto von Dentz
2011-05-18 15:58 ` [PATCH 3/3] Change append to prepend in pull_newmissedcalls Dmitriy Paliy
2011-05-19  7:27 ` [PATCH 1/3] Move phonebook_req_finalize Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.