summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2009-06-15 23:35:33 +0200
committerSamuel Lidén Borell <samuel@slbdata.se>2010-01-02 22:30:07 +0100
commit3aff8b355f4394b95f129390a00f6c440683f6ef (patch)
tree95084625c81c4d1e1975020dbc379351a162918f /plugin
parent291f0bea74ac83fbb00daf1cd234c7573beb1130 (diff)
downloadfribid-3aff8b355f4394b95f129390a00f6c440683f6ef.tar.gz
fribid-3aff8b355f4394b95f129390a00f6c440683f6ef.tar.bz2
fribid-3aff8b355f4394b95f129390a00f6c440683f6ef.zip
Allocate strings that are freed by the browser with NPN_MemAlloc
Diffstat (limited to 'plugin')
-rw-r--r--plugin/npmain.c4
-rw-r--r--plugin/npobject.c13
-rw-r--r--plugin/npobject.h1
3 files changed, 14 insertions, 4 deletions
diff --git a/plugin/npmain.c b/plugin/npmain.c
index 1b577a9..90f6674 100644
--- a/plugin/npmain.c
+++ b/plugin/npmain.c
@@ -52,10 +52,10 @@ NPError NPP_Destroy(NPP instance, NPSavedData **save) {
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
switch (variable) {
case NPPVpluginNameString:
- *((char**)value) = strdup("BankID e-legitimation");
+ *((char**)value) = "BankID e-legitimation";
return NPERR_NO_ERROR;
case NPPVpluginDescriptionString:
- *((char**)value) = strdup("Insticksmodul för BankID e-legitimation");
+ *((char**)value) = "Insticksmodul för BankID e-legitimation";
return NPERR_NO_ERROR;
case NPPVpluginScriptableNPObject:
*((NPObject**)value) = (NPObject*)instance->pdata;
diff --git a/plugin/npobject.c b/plugin/npobject.c
index e8e9c30..fc500f8 100644
--- a/plugin/npobject.c
+++ b/plugin/npobject.c
@@ -50,6 +50,15 @@ static char *strndup(const char *source, int maxLength) {
return ret;
}
+// Re-allocates a string with NPN_MemAlloc instead of malloc
+char *npstr(char *source) {
+ int size = strlen(source)+1;
+ char *dest = NPN_MemAlloc(size);
+ memcpy(dest, source, size);
+ free(source);
+ return dest;
+}
+
static bool getProperty(NPP instance, NPObject *obj, const char *name, NPVariant *result) {
NPIdentifier ident = NPN_GetStringIdentifier(name);
return NPN_GetProperty(instance, obj, ident, result);
@@ -184,7 +193,7 @@ static bool objInvoke(NPObject *npobj, NPIdentifier ident,
switch (this->plugin->type) {
case PT_Version:
if (!strcmp(name, "GetVersion") && (argCount == 0)) {
- char *s = version_getVersion(this->plugin);
+ char *s = npstr(version_getVersion(this->plugin));
STRINGZ_TO_NPVARIANT(s, *result);
return true;
}
@@ -196,7 +205,7 @@ static bool objInvoke(NPObject *npobj, NPIdentifier ident,
// Get parameter
char *param = strndup(NPVARIANT_TO_STRING(args[0]).utf8characters, NPVARIANT_TO_STRING(args[0]).utf8length);
- char *s = sign_getParam(this->plugin, param);
+ char *s = npstr(sign_getParam(this->plugin, param));
free(param);
STRINGZ_TO_NPVARIANT(s, *result);
diff --git a/plugin/npobject.h b/plugin/npobject.h
index 69bde5b..214ac63 100644
--- a/plugin/npobject.h
+++ b/plugin/npobject.h
@@ -36,6 +36,7 @@ typedef struct {
Plugin *plugin;
} PluginObject;
+char *npstr(char *source);
NPObject *npobject_fromMIME(NPP instance, NPMIMEType mimeType);
#endif