diff --git a/python/core/qgsreadwritecontext.sip.in b/python/core/qgsreadwritecontext.sip.in
index 34bed2238e3..e9d851195e2 100644
--- a/python/core/qgsreadwritecontext.sip.in
+++ b/python/core/qgsreadwritecontext.sip.in
@@ -116,7 +116,7 @@ This would happen when it gets out of scope.
 #include "qgsreadwritecontext.h"
 %End
   public:
-    QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context );
+    QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context );
 %Docstring
 Creates a popper
 %End
diff --git a/src/core/qgsreadwritecontext.cpp b/src/core/qgsreadwritecontext.cpp
index cdda338a065..4baa772c16e 100644
--- a/src/core/qgsreadwritecontext.cpp
+++ b/src/core/qgsreadwritecontext.cpp
@@ -41,7 +41,7 @@ QgsReadWriteContextCategoryPopper QgsReadWriteContext::enterCategory( const QStr
   if ( !details.isEmpty() )
     message.append( QString( " :: %1" ).arg( details ) );
   mCategories.push_back( message );
-  return QgsReadWriteContextCategoryPopper( this );
+  return QgsReadWriteContextCategoryPopper( *this );
 }
 
 void QgsReadWriteContext::leaveCategory()
diff --git a/src/core/qgsreadwritecontext.h b/src/core/qgsreadwritecontext.h
index abd3b79743b..7e20caf14b5 100644
--- a/src/core/qgsreadwritecontext.h
+++ b/src/core/qgsreadwritecontext.h
@@ -124,14 +124,10 @@ class CORE_EXPORT QgsReadWriteContextCategoryPopper
 {
   public:
     //! Creates a popper
-    QgsReadWriteContextCategoryPopper( QgsReadWriteContext *context ) : mContext( context ) {}
-    ~QgsReadWriteContextCategoryPopper()
-    {
-      if ( mContext )
-        mContext->leaveCategory();
-    }
+    QgsReadWriteContextCategoryPopper( QgsReadWriteContext &context ) : mContext( context ) {}
+    ~QgsReadWriteContextCategoryPopper() {mContext.leaveCategory();}
   private:
-    QgsReadWriteContext *mContext;
+    QgsReadWriteContext &mContext;
 };
 
 #endif // QGSREADWRITECONTEXT_H