Bug 1491824 - [Wayland/Clipboard] Clipboard minor fixes, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Tue, 18 Sep 2018 15:12:02 +0000
changeset 436997 3112727237aa9be9115b60f874f83caa55bd9a0f
parent 436996 391f1d4d5cda5e493caefa9d78bc665452499e07
child 436998 d972ccfe657d1d150bf226535017287e203b57eb
push id34667
push useraiakab@mozilla.com
push dateWed, 19 Sep 2018 02:13:23 +0000
treeherdermozilla-central@3857cbe7b717 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1491824
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1491824 - [Wayland/Clipboard] Clipboard minor fixes, r=jhorak when g_io_channel_set_encoding() fails we return invalid/uninitialized clipboardData, so initialize clipboardData explicitly. When SetClipboardDataOffer() is called with null aWaylandDataOffer, delete our recent clipboard content and not throw an error message. Differential Revision: https://phabricator.services.mozilla.com/D6039
widget/gtk/nsClipboardWayland.cpp
--- a/widget/gtk/nsClipboardWayland.cpp
+++ b/widget/gtk/nsClipboardWayland.cpp
@@ -148,17 +148,17 @@ DataOffer::GetData(wl_display* aDisplay,
     int ret = poll(&fds, 1, kClipboardTimeout / 1000);
     if (!ret || ret == -1) {
         close(pipe_fd[0]);
         return nullptr;
     }
 
     GIOChannel *channel = g_io_channel_unix_new(pipe_fd[0]);
     GError* error = nullptr;
-    char* clipboardData;
+    char* clipboardData = nullptr;
 
     g_io_channel_set_encoding(channel, nullptr, &error);
     if (!error) {
         gsize length = 0;
         g_io_channel_read_to_end(channel, &clipboardData, &length, &error);
         if (length == 0) {
             // We don't have valid clipboard data although
             // g_io_channel_read_to_end() allocated clipboardData for us.
@@ -465,23 +465,27 @@ nsRetrievalContextWayland::RegisterNewDa
 }
 
 void
 nsRetrievalContextWayland::SetClipboardDataOffer(wl_data_offer *aWaylandDataOffer)
 {
     // Delete existing clipboard data offer
     mClipboardOffer = nullptr;
 
-    DataOffer* dataOffer =
-        static_cast<DataOffer*>(g_hash_table_lookup(mActiveOffers,
-                                                    aWaylandDataOffer));
-    NS_ASSERTION(dataOffer, "We're missing clipboard data offer!");
-    if (dataOffer) {
-        g_hash_table_remove(mActiveOffers, aWaylandDataOffer);
-        mClipboardOffer = dataOffer;
+    // null aWaylandDataOffer indicates that our clipboard content
+    // is no longer valid and should be release.
+    if (aWaylandDataOffer != nullptr) {
+        DataOffer* dataOffer =
+            static_cast<DataOffer*>(g_hash_table_lookup(mActiveOffers,
+                                                        aWaylandDataOffer));
+        NS_ASSERTION(dataOffer, "We're missing stored clipboard data offer!");
+        if (dataOffer) {
+            g_hash_table_remove(mActiveOffers, aWaylandDataOffer);
+            mClipboardOffer = dataOffer;
+        }
     }
 }
 
 void
 nsRetrievalContextWayland::SetPrimaryDataOffer(
       gtk_primary_selection_offer *aPrimaryDataOffer)
 {
     // Release any primary offer we have.