Skip to content

Commit 4a632a6

Browse files
gahrbadboy
authored andcommitted
Make sure to disconnect the adapter in the destructor
1 parent 9069b14 commit 4a632a6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

adapters/qt.h

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*-
22
* Copyright (C) 2014 Pietro Cerutti <[email protected]>
3-
*
3+
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
66
* are met:
@@ -9,7 +9,7 @@
99
* 2. Redistributions in binary form must reproduce the above copyright
1010
* notice, this list of conditions and the following disclaimer in the
1111
* documentation and/or other materials provided with the distribution.
12-
*
12+
*
1313
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1414
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1515
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -69,19 +69,27 @@ class RedisQtAdapter : public QObject {
6969
}
7070

7171
public:
72-
RedisQtAdapter(QObject * parent = 0)
72+
RedisQtAdapter(QObject * parent = 0)
7373
: QObject(parent), m_ctx(0), m_read(0), m_write(0) { }
7474

75-
~RedisQtAdapter() { }
75+
~RedisQtAdapter() {
76+
if (m_ctx != 0) {
77+
m_ctx->ev.data = NULL;
78+
}
79+
}
7680

77-
void setContext(redisAsyncContext * ac) {
81+
int setContext(redisAsyncContext * ac) {
82+
if (ac->ev.data != NULL) {
83+
return REDIS_ERR;
84+
}
7885
m_ctx = ac;
7986
m_ctx->ev.data = this;
8087
m_ctx->ev.addRead = RedisQtAddRead;
8188
m_ctx->ev.delRead = RedisQtDelRead;
8289
m_ctx->ev.addWrite = RedisQtAddWrite;
8390
m_ctx->ev.delWrite = RedisQtDelWrite;
8491
m_ctx->ev.cleanup = RedisQtCleanup;
92+
return REDIS_OK;
8593
}
8694

8795
private:

examples/example-qt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ExampleQt : public QObject {
1313

1414
signals:
1515
void finished();
16-
16+
1717
public slots:
1818
void run();
1919

0 commit comments

Comments
 (0)