Fix deleting SDP records when a device is removed

This fixes the issues of stale SDP records, when the SDP records are
modified on the remote end, before the next connection. Since we are going
to perform SDP on the next connection anyway, this doesn't introduce any
new overheads.
diff --git a/src/device.c b/src/device.c
index 6cb9641..5585271 100644
--- a/src/device.c
+++ b/src/device.c
@@ -937,10 +937,12 @@
 
 	adapter_get_address(device->adapter, &src);
 	ba2str(&device->bdaddr, addr);
+
 	if (device->paired)
 		device_remove_bonding(device);
 	delete_entry(&src, "profiles", addr);
 	delete_entry(&src, "trusts", addr);
+	delete_all_records(&src, &device->bdaddr);
 }
 
 void device_remove(struct btd_device *device, gboolean remove_stored)
diff --git a/src/storage.c b/src/storage.c
index 5760656..5edccf8 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -913,6 +913,25 @@
 	rec_list->recs = sdp_list_append(rec_list->recs, rec);
 }
 
+void delete_all_records(bdaddr_t *src, bdaddr_t *dst)
+{
+	sdp_list_t *records, *seq;
+	char srcaddr[18], dstaddr[18];
+
+	ba2str(src, srcaddr);
+	ba2str(dst, dstaddr);
+
+	records = read_records(src, dst);
+
+	for (seq = records; seq; seq = seq->next) {
+		sdp_record_t *rec = seq->data;
+		delete_record(srcaddr, dstaddr, rec->handle);
+	}
+
+	if (records)
+		sdp_list_free(records, (sdp_free_func_t) sdp_record_free);
+}
+
 sdp_list_t *read_records(bdaddr_t *src, bdaddr_t *dst)
 {
 	char filename[PATH_MAX + 1];
diff --git a/src/storage.h b/src/storage.h
index 3159f2a..6e40151 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -63,6 +63,7 @@
 sdp_record_t *record_from_string(const gchar *str);
 sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle);
 int delete_record(const gchar *src, const gchar *dst, const uint32_t handle);
+void delete_all_records(bdaddr_t *src, bdaddr_t *dst);
 sdp_list_t *read_records(bdaddr_t *src, bdaddr_t *dst);
 sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
 int store_device_id(const gchar *src, const gchar *dst,